The Gateway to Computer Science Excellence
+1 vote
323 views

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 Loyal (8.3k points) | 323 views
+4

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

0

@  Anu007 

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

0
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).

by Boss (35.6k points)
selected by
0
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
50,648 questions
56,429 answers
195,205 comments
99,907 users