Binary Search Algorithm
Binary Search Algorithm
Search Algorithms
Search Algorithms
There are many situations where we need to
search for specific things. An example is when you look someone up in a phone book. You have been using an algorithm without realising it. We are now going to look at different search algorithms.
Search Algorithms
In your pairs get one person to think of a number
between 1 and 99, keeping it secret. The other person needs to ask questions which have a yes or no answer to locate that number. What is the min/max and average number of questions that need to be answered to locate the number? Can you describe an efficient algorithm? Min = 1 Max = 98 Best method is to half known range each time.
list. The list must be in alphabetical or numerical order. The algorithm hinges around the middle item of a sub list. The middle item is defined as 0.5(n1+n2) Where n1 is the first item in the sub list and n2 is the last.
a) Dixon b) Davy
1) Abbot
Iteration 1
Middle = 1 ( 1 + 11) = 6th 2 = Daniel
2) Brown 3) Carr 4) Casson 5) Cater 6) Daniel 7) Dixon 8) Domb 9) Fox 10) Gough 11) Hampton
3rd Iteration
7) Dixon 8) Domb
1st Iteration
Middle = 1 ( 1 + 11) = 6th 2 = Daniel
3rd Iteration
7) Dixon 8) Domb
the number of data items is 3, 7, 15, 31, 63. Can you see why? The sequence has nth term 2n-1 Each sub list is always odd and part of the same sequence, so when you add one and half it works perfectly. In some cases it can be beneficial to add a dummy item to make the list up to 2n -1.
1) 2) 3) 4) 5) 6) 7) 8)