lecture05 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 5 Prof. Erik Demaine
Background image of page 1

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 8 L5.2 © 2001 by Charles E. Leiserson How fast can we sort? All the sorting algorithms we have seen so far are comparison sorts : only use comparisons to determine the relative order of elements. E.g ., insertion sort, merge sort, quicksort, heapsort. The best worst-case running time that we’ve seen for comparison sorting is O ( n lg n ) . Is O(nlgn) the best we can do? Decision trees can help us answer this question.
Background image of page 2
Introduction to Algorithms Day 8 L5.3 © 2001 by Charles E. Leiserson Decision-tree example 1:2 1:2 2:3 2:3 123 123 1:3 1:3 132 132 312 312 1:3 1:3 213 213 2:3 2:3 231 231 321 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a i a j . The right subtree shows subsequent comparisons if a i a j . Sort a 1 , a 2 , …, a n
Background image of page 3

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 8 L5.4 © 2001 by Charles E. Leiserson Decision-tree example 1:2 1:2 2:3 2:3 123 123 1:3 1:3 132 132 312 312 1:3 1:3 213 213 2:3 2:3 231 231 321 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a i a j . The right subtree shows subsequent comparisons if a i a j . 9 4 Sort a 1 , a 2 , a 3 = ⟨ 9, 4, 6 :
Background image of page 4
Introduction to Algorithms Day 8 L5.5 © 2001 by Charles E. Leiserson Decision-tree example 1:2 1:2 2:3 2:3 123 123 1:3 1:3 132 132 312 312 1:3 1:3 213 213 2:3 2:3 231 231 321 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a i a j . The right subtree shows subsequent comparisons if a i a j . 9 6 Sort a 1 , a 2 , a 3 = ⟨ 9, 4, 6 :
Background image of page 5

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 8 L5.6 © 2001 by Charles E. Leiserson Decision-tree example 1:2 1:2 2:3 2:3 123 123 1:3 1:3 132 132 312 312 1:3 1:3 213 213 2:3 2:3 231 231 321 321 Each internal node is labeled i : j for i , j {1, 2,…, n } . The left subtree shows subsequent comparisons if a i a j . The right subtree shows subsequent comparisons if a i a j . 4 6 Sort a 1 , a 2 , a 3 = ⟨ 9, 4, 6 :
Background image of page 6
Introduction to Algorithms Day 8 L5.7 © 2001 by Charles E. Leiserson Decision-tree example 1:2 1:2 2:3 2:3 123 123 1:3 1:3 132 132 312 312 1:3 1:3 213 213 2:3 2:3 231 231 321 321 Each leaf contains a permutation π(1) , π(2) ,…, π ( n ) to indicate that the ordering a π (1) a π (2) L a π (n) has been established. 4 6 9 Sort a 1 , a 2 , a 3 = ⟨ 9, 4, 6 :
Background image of page 7

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 8 L5.8 © 2001 by Charles E. Leiserson Decision-tree model A decision tree can model the execution of any comparison sort: One tree for each input size n . View the algorithm as splitting whenever it compares two elements. The tree contains the comparisons along all possible instruction traces. The running time of the algorithm = the length of the path taken.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 47

lecture05 - Introduction to Algorithms...

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

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