Complexity Analysis for Grid class Analyze the best casewors
Solution
Please follow the data and description :
The term best-case performance is used in the stream of the computer science as to describe an algorithm\'s behavior under the optimal conditions. For example, the best case for a simple linear search on a list occurs when the desired element is the first element of the list.
16) searchIndex : It is used to search for an index in the given value from the user. The complexity for this method in the best case for there are n items is OPTION B ((n)).
17) For the same method the worst case is also the same OPTION B (O(n)).
18) insert2End : This method is used to enter the element or to insert the element to the end of the list. So the complexity in the best case is given as (1). So the answer is OPTION A ((1)).
19) delete : This method is used to delete an element desired by the user based on the index values. So the complexity of the algorithm is given as (1). So the answer is OPTION A ((1)).
20) For the same method the worst case is given as O(1). So the answer is OPTION A (O(1)).
21) deleteFromHead : This method is used to delete an element from the head based on the index values. So the complexity of the algorithm is given as (1). So the answer is OPTION A ((1)).
22) For the same method the worst case is given as O(1). So the answer is OPTION A (O(1)).
23) deleteFromEnd : This method is used to delete an element from the end based on the index values. So the complexity of the algorithm is given as (1). So the answer is OPTION A ((1)).
24) For the same method the worst case is given as O(1). So the answer is OPTION A (O(1)).
25) str : This method is to print the data to string to console. So the complexity is given by (n) for n elements. So the answer is OPTION B ((n)).
NOTE :
In order to delete a node and connect the previous and the next node together, we need to know their pointers. In a doubly-linked list, both pointers are available in the node that is to be deleted. The time complexity is constant in this case, i.e., O(1).
Hope this is helpful.
