The Gateway to Computer Science Excellence
+1 vote

You have an array of n  elements. Suppose you implement quick sort by always choosing the central element of the array as the pivot. Then the tightest lower bound for the best case performance is

a) O(n2)

b) O(nlogn)

c) Θ(nlogn)

d) O(n3)

in Algorithms by | 495 views

Best : $\Omega \left ( nlogn \right )$  worst = O(n2)


@  Anu007 

In best case upper bound will be O(n2)?

It is normal quick sort in which we are selecting the middle element as the pivot so the best case will be that it is divided into two equal parts giving the time complexity of O(nlogn).

In the worst case the it will take O(n^2) as the middle element selected can divide the array into two parts of  0    element at one side and n-1 at other.

now in the question it is asking for the lower bound in the best case.

the time complexity in best case is O(nlogn)

now tightest lower bound means the least possible time in which the problem can be solved.

in this case tightest lower bound is O(nlogn).

1 Answer

+2 votes
Best answer

 best case= o(nlogn)

If we choose central element as pivot then array is divided into two equal part. And recurrence relation become T(n)=2T(n/2)+n which will take o(nlogn) time. 

Worst case  =o(n^2).

If we choose central element as pivot then array is divided into two part one part contain 0 element and other part is n-1 element.  And recurrence relation become T(n)=T(n-1)+1 which will take o(n^2).

selected by
Worst case recurrenct relation is T(n) = T(n-1) + n not T(n) = T(n-1) + 1. According to your recurrence relation, time complexity will become O(n).

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,501 answers
95,325 users