Lecture8

Lecture8 - Lecture 8, Oct 14 2010 Sorting using heaps We...

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

View Full Document Right Arrow Icon
1 Sorting using heaps We can first build heap, then repeat: remove max . Lecture 8, Oct 14 2010 In place: BuildHeap for i=n down to 2 exch A(1), A(i) Heapify(A,1,i-1) Essentially same as the first approach. 93 We use the fact that: » heap becomes smaller after “remove max”, » last array entry becomes free. Example Sort: 8 5 7 3 2 1 ? 1 5 7 3 2 8 ? 7 5 1 3 2 8 ? 2 5 1 exchange exchange heapify 5 3 1 heapify 94 3 7 8 ? 2 7 8 ?
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Lower bound for sorting All sorting algs that we saw : comparison-sorts only operation allowed on data is comparison. Is O(n log n) the best we can do in this case ? Represent computation by decision tree : 95 Here 1:2 means compare first with second input; <3,1,2> means that third element was the minimum, 2 nd was the maximum. Execution - walk from root to a leaf; longest walk – worst case time More lower bound 1 leaf per each possible answer. n! different answers at least n! leaves.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Lecture8 - Lecture 8, Oct 14 2010 Sorting using heaps We...

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

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