retagged by
487 views
0 votes
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?
retagged by

1 Answer

1 votes
1 votes

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) 

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

Related questions

0 votes
0 votes
1 answer
1
tusharb asked Feb 18, 2022
695 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 votes
0 votes
1 answer
2
LavTheRawkstar asked Jan 12, 2017
835 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[...
0 votes
0 votes
0 answers
4
Çșȇ ʛấẗẻ asked May 11, 2023
299 views