lecture05

# lecture05 - Introduction to Algorithms...

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

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 5 Prof. Erik Demaine

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

View Full Document
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.
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

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

View Full Document
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 :
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 :

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

View Full Document
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 :
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 :

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 47

lecture05 - Introduction to Algorithms...

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

View Full Document
Ask a homework question - tutors are online