• retagged by
1,283 views
0 0 votes
suppose we are given a sorted array ....and we need to extract minimum every tym  what is the time complexity??

and what is the tym complexity to delete the minimum ? are they both same ??

and what is the tym complexity to delete an element?

1 Answer

1 1 vote

suppose the array is sorted in ASCENDING ORDER : 

--------------------------------------------------------------------------------------------

1)to extract one minimum time taken is O(1) but than all the elements will be shifted which will cost O(n-1).

similarly if we extract all elements it will cost O(n-2) + O(1)+ O(n-3) + O(1) + O(n-4) +.... .................O(1)= O(n2)

-----------------------------------------------------------------------------------------------

2)to delete the minimum O(1) to delete and O(n-1) to left shift all element. = O(n) . yes they are same if we perform for only one element.

-----------------------------------------------------------------------------------------------

3) to delete maxm element : O(1)

    to delete any specific element(worst case  = O(n) 

----------------------------------------------------------------------------------------------

Position:
Show:

Related questions

0 0 votes
1 1 answer
1.6k
1.6k views
tusharb asked Feb 18, 2022
1,649 views
As we know the time complexity of solving the greedy knapsack algorithm depends mainly on the sorting algorithm used, Can we use counting sort as the sorting algorithm to...
0 0 votes
1 1 answer
1.3k
1.3k views
LavTheRawkstar asked Jan 12, 2017
1,301 views
INSERTION-SORT (A, n) ⊳ A[1 . . n]for (j ← 2 to len(A) ){key ← A[ j];i ← j – 1 ; while (i 0 and A[i] key) { A[i+1] ← A[i...
8 8 votes
6 6 answers
3.9k
3.9k views
Arjun asked Feb 27, 2025
3,927 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
0 0 votes
1 answers 1 answer
897
897 views
Mrityudoot asked Mar 7, 2024
897 views
For flag based approach in Bubble sort we can check first by a flag if the list is sorted or not in O(n), and if it is sorted, then no need to sort and the operation ends...