CS 100 M Lecture 24 - 24. Divide and Conquer Algorithms...

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

View Full Document Right Arrow Icon
24. Divide and Conquer Algorithms Binary Search Merge Sort Mesh Generation Recursion
Background image of page 1

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

View Full DocumentRight Arrow Icon
Question The Manhatten phone book has 1,000,000+ entries. How is it possible to locate a name by examining just a tiny , tiny fraction of those entries?
Background image of page 2
Answer: Repeated Halving To find the page containing Derek Jeter’s number… while (Phone book is longer than 1 page) Open to the middle page. if “Jeter” comes before the first name, Rip and throw away the 2 nd half. else Rip and throw away the 1 st half. end end
Background image of page 3

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

View Full DocumentRight Arrow Icon
What Happens to Phone Book Length… Original: 3000 pages After 1 rip: 1500 pages After 2 rips: 750 pages After 3 rips: 375 pages After 4 rips: 188 pages After 5 rips: 94 pages After 12 rips: 1 page
Background image of page 4
Binary Search The idea of repeatedly halving the size of the “search space” is the main idea behind the method of binary search. An item in a sorted array of length n can be located with just log 2 n comparisons.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Problem Search a Sorted Array For a Given Value (We assume that the array has no repeated elements.)
Background image of page 6
12 15 35 33 42 45 51 73 62 75 86 98 Binary Search: a = 70 x: L: Mid: R: 1 6 12 1 2 3 4 5 6 7 8 9 10 11 12 x(Mid) <= a So throw away the left half…
Background image of page 7

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

View Full DocumentRight Arrow Icon
12 15 35 33 42 45 51 73 62 75 86 98 Binary Search: a = 70 x: L: Mid: R: 6 9 12 1 2 3 4 5 6 7 8 9 10 11 12 a < x(Mid) So throw away the right half…
Background image of page 8
12 15 35 33 42 45 51 73 62 75 86 98 Binary Search: a = 70 x: L: Mid: R: 6 7 9 1 2 3 4 5 6 7 8 9 10 11 12 x(Mid) <= a So throw away the left half…
Background image of page 9

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

View Full DocumentRight Arrow Icon
12 15 35 33 42 45 51 73 62 75 86 98 Binary Search: a = 70 x: L: Mid: R: 7 8 9 1 2 3 4 5 6 7 8 9 10 11 12 x(Mid) <= a So throw away the left half…
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2008 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).

Page1 / 59

CS 100 M Lecture 24 - 24. Divide and Conquer Algorithms...

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

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