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

asked in Algorithms by (275 points)   | 26 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 (5.8k points)  
edited by
Top Users Jan 2017
  1. Debashish Deka

    9716 Points

  2. sudsho

    5560 Points

  3. Bikram

    5290 Points

  4. Habibkhan

    4990 Points

  5. Vijay Thakur

    4498 Points

  6. Arjun

    4418 Points

  7. saurabh rai

    4236 Points

  8. Sushant Gokhale

    4226 Points

  9. Kapil

    3848 Points

  10. santhoshdevulapally

    3808 Points

Monthly Topper: Rs. 500 gift card

19,449 questions
24,228 answers
53,954 comments
20,373 users