Sorting Quiz 1

What is recurrence for worst case of QuickSort and what is the time complexity in Worst case?

A. Recurrence is T(n) = T(n-2) + O(n) and time complexity is O(n²)

B. Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n²)

C. Recurrence is T(n) = 2T(n/2) + O(n) and time complexity is O(nLogn)

D. Recurrence is T(n) = T(n/10) + T(9n/10) + O(n) and time complexity is O(nLogn)

Solution :

B) is correct.

The worst case of QuickSort occurs when the picked pivot is always one of the corner elements in sorted array. In worst case, QuickSort recursively calls one subproblem with size 0 and other subproblem with size (n-1). So recurrence is

T(n) = T(n-1) + T(0) + O(n)

The above expression can be rewritten as

T(n) = T(n-1) + O(n)

Below we can see the implementation of QuickSort :

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

DeCoding DeFi

Array.finance Newsletter #2

Setting up a Spark Cluster on RHEL7 Linux

Distributed load testing in JMeter

Cool and Useful Ruby Methods

Learning Algo & DS

Alcobuddy: A Story based Approach to Understanding Cloud Native Applications

CodePipeline Deploy Cross Account

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Dinner Hand Shakes Puzzle

Data Structures, Algorithms and Our Real life — Part 1

One interview, Many learnings

Interview preparation -DSA #day1