The Gateway to Computer Science Excellence
For all GATE CSE Questions
Toggle navigation
Email or Username
Password
Remember
Login
Register

I forgot my password
Activity
Questions
Unanswered
Tags
Subjects
Users
Ask
Prev
Blogs
New Blog
Exams
quick sort time complexity
+1
vote
3k
views
the worst case time complexity of quicksort for an elements when the median is selected as the pivot
a. o(n^2)
b.o(n)
c.o(nlogn)
d.o(logn)
algorithms
timecomplexity
quicksort
asked
Mar 9, 2016
in
Algorithms
by
akankshay

3k
views
answer
comment
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
1
Answer
+3
votes
Best answer
Answer C) O(nlogn), when median selected as pivot, partition method will divide array into equal halves.. so logn level recursion tree will form with cn work(partition method) at each level..
The recurence would be..
T(n) = 2T(n/2) + Θ(n)
Therefore total time complexity =Θ(nlogn) in all cases
Note:O(n) time algo available for median finding
https://en.m.wikipedia.org/wiki/Median_of_medians
answered
Mar 9, 2016
by
Anurag_s
edited
Mar 10, 2016
by
abhilashpanicker29
comment
0
can you tell the algo, which gives median in O(n) time?
+1
https://en.m.wikipedia.org/wiki/Median_of_medians
0
Thanks :)
0
What if all elements are equal
0
then also O(nlogn)
0
@prashant can u explain. How it will be O(nlogn) when all elements are same
0
same recurrence relation will be applied here also
0
if all elements are same then worst case partitioning will occur. How O(nlogn) then?
0
Here it doesn't matter all the elements are same or not because it will divide the array in two equal parts which gives the recurrence relation for best case of quick sort
Please
log in
or
register
to add a comment.
← Prev.
Next →
← Prev. Qn. in Sub.
Next Qn. in Sub. →
Related questions
+1
vote
2
answers
1
Quick Sort Time Complexity
Quick sort gives O(nlogn) worst case performance if the pivot is selected as: a) First element of the array b) Median of first, last and middle elements c) Arithmetic mean of the elements d) None of these Now, the answer is given as Option (b). But, ... order of elements and not on pivot element. So, answer should be option (d) i.e None of these Correct me if I am wrong
asked
Jul 2, 2018
in
Algorithms
by
garvit_vijai

896
views
quicksort
sorting
timecomplexity
0
votes
1
answer
2
Self Doubt  Quick Sort
Consider the following inputs: 1) 2 2 2 2 2 2 2 2) 1 2 3 4 5 6 7 3) 7 6 5 4 3 2 1 In all three cases, the worstcase time complexity of quicksort is O(n2) My doubt is if I am taking the middle element as a pivot, ... ), right? Can someone explain how we are saying worstcase time complexity for these three cases is O(n2) irrespective of the selection of the pivot element?
asked
Nov 17, 2018
in
Algorithms
by
garvit_vijai

106
views
algorithms
quicksort
timecomplexity
+1
vote
1
answer
3
quick sort
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)
asked
Jan 14, 2018
in
Algorithms
by
iarnav

473
views
quicksort
algorithms
sorting
timecomplexity
+3
votes
3
answers
4
Quick Sort
"Quick sort has good cache performance" , Can anyone explain this statement.How is cache related to quick sort.I searched for this over the internet but could not find a good article.
asked
Sep 3, 2017
in
Algorithms
by
Sourajit25

515
views
algorithms
sorting
timecomplexity
quicksort
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
Recent Posts
Interview Experience for MS(R)IIT Delhi (School of Information Technology)
How am I preparing
PGEE 2020 (CSE) Experience
IIT Tirupati MS Interview 2020
IIT Bombay Mtech RA  interview experience (2020)
Subjects
All categories
General Aptitude
2k
Engineering Mathematics
8.2k
Digital Logic
2.9k
Programming and DS
5k
Algorithms
4.4k
Theory of Computation
6.2k
Compiler Design
2.2k
Operating System
4.6k
Databases
4.2k
CO and Architecture
3.4k
Computer Networks
4.2k
Non GATE
1.2k
Others
1.5k
Admissions
595
Exam Queries
562
Tier 1 Placement Questions
23
Job Queries
71
Projects
19
Unknown Category
1k
Recent Blog Comments
........
After getting so many mails from you...
Refund will be given for such cases if applied...
@sreejit007 they don't publish any cutoff or...
@ranjanabhi Can you please elaborate what did...
Network Sites
GO Mechanical
GO Electrical
GO Electronics
GO Civil
CSE Doubts
52,315
questions
60,427
answers
201,757
comments
95,235
users