GATE CSE
First time here? Checkout the FAQ!
x
0 votes
36 views

asked in Algorithms by (275 points)   | 36 views

1 Answer

+2 votes

Choose the median in constant time, because the algorithm is implemented as an array and you can find the median in constant time.

Then, split the array with respect to the median.

The recurrence relation will be:

T(n) = 2T($\frac{n}{2}$) + 1

(1 because we are doing a constant work and then splitting the array)

Solve by master's theorem, you will get $\Theta (n)$

NOTE: If the data structure used was a linked list or if the elements were not in ascending order, the complexity would have been $\Theta (nlogn)$

answered by Boss (7.9k points)  
edited by


Top Users May 2017
  1. akash.dinkar12

    3146 Points

  2. pawan kumarln

    1608 Points

  3. sh!va

    1580 Points

  4. Arjun

    1326 Points

  5. Devshree Dubey

    1230 Points

  6. Angkit

    1028 Points

  7. Debashish Deka

    1012 Points

  8. Bikram

    970 Points

  9. LeenSharma

    810 Points

  10. srestha

    662 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. pawan kumarln

    234 Points

  2. Ahwan

    118 Points

  3. jjayantamahata

    106 Points

  4. joshi_nitish

    106 Points

  5. Aditya GN

    63 Points


22,722 questions
29,048 answers
65,039 comments
27,510 users