Download presentation

Presentation is loading. Please wait.

Published byBrendan Kimberly Modified over 2 years ago

1
Binary Search This algorithm is for finding an item in a sorted list or determining that it is not in the list. Is Mr Nosey in the list opposite? This algorithm is for finding an item in a sorted list or determining that it is not in the list. Is Mr Nosey in the list opposite? Mr Nosey? 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush 6. Mr Small 7. Mr Strong 8. Mr Tall 9. Mr Tickle 10. Mr Topsy-Turvy First find the middle of the list: (10+1)/2 = 5.5 so take 6 th item First find the middle of the list: (10+1)/2 = 5.5 so take 6 th item ? Compare Mr Nosey and Mr Small, Nosey comes before Small so reduce the list to the first half. Compare Mr Nosey and Mr Small, Nosey comes before Small so reduce the list to the first half.

2
Binary Search Mr Nosey? 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush 6. Mr Small 7. Mr Strong 8. Mr Tall 9. Mr Tickle 10. Mr Topsy-Turvy Now find the middle (1+5)/2 = 3 rd item Now find the middle (1+5)/2 = 3 rd item Compare Mr Nosey and Mr Happy, Nosey comes after Happy so reduce the list to the second half. Compare Mr Nosey and Mr Happy, Nosey comes after Happy so reduce the list to the second half. 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush ?

3
Binary Search Mr Nosey? 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush 6. Mr Small 7. Mr Strong 8. Mr Tall 9. Mr Tickle 10. Mr Topsy-Turvy Find the middle (4+5)/2 = 4.5 so take item 5 Find the middle (4+5)/2 = 4.5 so take item 5 Compare Mr Nosey and Mr Rush, Nosey comes before Rush so take first half of list 4. Mr Nosey 5. Mr Rush ? 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush

4
Binary Search Mr Nosey? 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush 6. Mr Small 7. Mr Strong 8. Mr Tall 9. Mr Tickle 10. Mr Topsy-Turvy Compare Mr Nosey and Mr Nosey, We have found him! Compare Mr Nosey and Mr Nosey, We have found him! 4. Mr Nosey 5. Mr Rush 1. Mr Greedy 2. Mr Grumpy 3. Mr Happy 4. Mr Nosey 5. Mr Rush 4. Mr Nosey ?

Similar presentations

OK

CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.

CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on success and failure rates Ppt on fair and lovely cream Ppt on media and democracy Download ppt on corrosion of metals Ppt on combination of resistances eve Ppt on student information system Ppt on economic order quantity method Ppt on steve jobs as entrepreneur Ppt on precautions of tsunami Download ppt on food security in india class 9