Quick-Sort Algorithm Analysis: Best, Average, and Worst Cases, Slides of Design and Analysis of Algorithms

An analysis of the quick-sort algorithm, discussing its best, average, and worst-case scenarios. The best case occurs when the input is already sorted or reversely sorted, resulting in a time complexity of o(nlogn). The average case assumes a split of 1/10: 9/10, leading to an average time complexity of o(nlogn). The worst case, with an unbalanced partition, results in a time complexity of o(n^2). The document also mentions that quick-sort sorts in-place and requires minimal additional space.

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dharmadaas
dharmadaas 🇮🇳

4.3

(55)

262 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
76
4
2
1 3
Quick-Sort(A, 0, 7)
Quick-Sort(A, 0, 7) , done!
5 6 8
7
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Quick-Sort Algorithm Analysis: Best, Average, and Worst Cases and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

76

Quick-Sort(A, 0, 7)

Quick-Sort(A, 0, 7)

, done!

77

Quick-Sort: Best Case

 Even Partition

Total time: (nlogn)

cn

2 × cn/2 = cn

4 × c/4 = cn

n/3 × 3c = cn

log n levels

n

n/

n/

n/

n/

n/ n/

79

Quick-Sort: an Average Case

 Suppose the split is 1/10 : 9/

Quick-Sort: an Average Case

cn

cn

cn

≤cn

n

0.1n

0.9n

0.01n

0.09n

0.09n

Total time: (nlogn)

0.81n

log

10

n

log

10/

n

≤cn

80

Quick-Sort Summary

 Time

 Most of the work done in partitioning.

 Average case takes (n log(n)) time.

 Worst case takes (n

2

) time

Space

 Sorts in-place, i.e., does not require additional

space