0% found this document useful (0 votes)
6 views

Quicksort Lecture4

Uploaded by

fa22bscs0068
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Quicksort Lecture4

Uploaded by

fa22bscs0068
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Design and Analysis of

Algorithms

Lecture: 9 Quicksort

Engr. Simran Melwani


Quicksort

• Quicksort, like merge sort, applies the divide-and-conquer approach

• Three-step divide-and-conquer process

• Divide

• Conquer

• Combine

• Despite this slow worst-case running time, quicksort is often the best practical choice for sorting because it is
remarkably efficient on the average: its expected running time is O(n logn) and the constant factors hidden in the
notation O(n logn) are quite small.
QuickSort

• To sort an entire array A ,the initial call is QUICKSORT (A, 1, A.length).


Partitioning the Array

In this partitioning scheme:


• We select a pivot element (usually the last element in
the array).
• The array is rearranged so that all elements less than
or equal to the pivot are on the left of the pivot, and all
elements greater than the pivot are on the right.
Performance of Quicksort
•Best-case time complexity: O(n log n)
•Worst-case time complexity: O(n²)
•Best-case space complexity: O(log n)
•Worst-case space complexity: O(n)
Thank you

You might also like