04-Quicksort

04-Quicksort - Algorithms LECTURE 4 Quicksort Divide and...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Algorithms L4.1 Professor Ashok Subramanian L ECTURE 4 Quicksort Divide and conquer Partitioning Worst-case analysis Intuition Randomized quicksort Analysis Algorithms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.2 Quicksort Proposed by C.A.R. Hoare in 1962. Divide-and-conquer algorithm. Sorts “in place” (like insertion sort, but not like merge sort). Very practical (with tuning).
Background image of page 2
Algorithms L4.3 Divide and conquer Quicksort an n -element array: 1. Divide: Partition the array into two subarrays around a pivot x such that elements in lower subarray x elements in upper subarray. 1. Conquer: Recursively sort the two subarrays. 2. Combine: Trivial. x x x Key: Linear-time partitioning subroutine.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.4 x Running time = O ( n ) for n elements. Partitioning subroutine P ARTITION ( A , p , q ) A [ p . . q ] x A [ p ] pivot = A [ p ] i p for j p + 1 to q do if A [ j ] x then i i + 1 exchange A [ i ] A [ j ] exchange A [ p ] A [ i ] return i x x ? p i q j Invariant:
Background image of page 4
Algorithms L4.5 Example of partitioning i j 6 10 13 5 8 3 2 11
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.6 Example of partitioning i j 6 10 13 5 8 3 2 11
Background image of page 6
Algorithms L4.7 Example of partitioning i j 6 10 13 5 8 3 2 11
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.8 Example of partitioning 6 10 13 5 8 3 2 11 i j 6 5 13 10 8 3 2 11
Background image of page 8
Algorithms L4.9 Example of partitioning 6 10 13 5 8 3 2 11 i j 6 5 13 10 8 3 2 11
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.10 Example of partitioning 6 10 13 5 8 3 2 11 i j 6 5 13 10 8 3 2 11
Background image of page 10
Algorithms L4.11 Example of partitioning 6 10 13 5 8 3 2 11 i j 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.12 Example of partitioning 6 10 13 5 8 3 2 11 i j 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11
Background image of page 12
Algorithms L4.13 Example of partitioning 6 10 13 5 8 3 2 11 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11 i j 6 5 3 2 8 13 10 11
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.14 Example of partitioning 6 10 13 5 8 3 2 11 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11 i j 6 5 3 2 8 13 10 11
Background image of page 14
Algorithms L4.15 Example of partitioning 6 10 13 5 8 3 2 11 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11 i j 6 5 3 2 8 13 10 11
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms L4.16 Example of partitioning 6 10 13 5 8 3 2 11 6 5 3 10 8 13 2 11 6 5 13 10 8 3 2 11 6 5 3 2 8 13 10 11 i 2 5 3 6 8 13 10 11
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 47

04-Quicksort - Algorithms LECTURE 4 Quicksort Divide and...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online