Decision Maths - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Decision Maths

Description:

There are many situations where we need to search for ... 3) Robert 3) James. 4) Peter 4) Katie. 5) Claire 5) Lou. 6) Polly 6) Pamela. 7) Nick. 8) Caroline ... – PowerPoint PPT presentation

Number of Views:136
Avg rating:3.0/5.0
Slides: 16
Provided by: bengr1
Category:
Tags: decision | maths | polly

less

Transcript and Presenter's Notes

Title: Decision Maths


1
Decision Maths
  • Lesson 13 Search Algorithms

2
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.

3
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.

4
Linear Search Algorithm
  • This is the easiest of the search algorithms.
  • You basically search each item in the list till
    you find the one that satisfies your criteria.
  • There is no restriction on the data and it can be
    in any order.
  • This is however the least efficient search
    algorithm.
  • Especially if the item you are searching for is
    not on the list.
  • Imagine trying to locate someones details from
    the phone book if you only know their telephone
    number.
  • It is usually worth ordering the data to suit
    your needs.
  • Give some examples of sorting methods that you
    have seen.
  • How would you locate a name in the phone book.
  • How would you find a library book
  • How would you locate your name in the school
    register.

5
Search Algorithms
  • Phone books are ordered alphabetically on the
    first letter of surname then second then third
    etc.
  • benn
  • carl
  • caroline
  • cherice
  • Library books can be categorised, then ordered by
    the author, then the book title.
  • Class lists, by year, by tutor, alphabetical.

6
Indexed Sequential Search Algorithm
  • The data are first ordered and then subdivided.
  • An extra list or index is created using the first
    or last item in the subdivision
  • In the same way as the examples on the last
    slide.
  • This method is used in phone books and
    dictionaries.
  • The index appears at the top corner of the page.
  • If you are searching for horse in the
    dictionary you first flick through the pages to
    locate H, then you would perform a linear
    search on that page.

7
Binary Search Algorithm
  • Used to search and locate a specific item in a
    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(n1n2)
  • Where n1 is the first item in the sub list and n2
    is the last.

8
Binary Search Algorithm
  • Locate the names below in the list shown.
  • a) Dixon
  • b) Davy
  • 1) Abbot
  • 2) Brown
  • 3) Carr
  • 4) Casson
  • 5) Cater
  • 6) Daniel
  • 7) Dixon
  • 8) Domb
  • 9) Fox
  • 10) Gough
  • 11) Hampton

Iteration 1
Middle 1 ( 1 11) 6th
2
Daniel
9
Binary Search Algorithm
2nd Iteration
Middle 1 ( 7 11) 9th
7) Dixon
2
8) Domb
9) Fox
Fox
10) Gough
11) Hampton
Dixon is before Fox
3rd Iteration
Middle 1 ( 7 8) 7.5th 8th
2
7) Dixon
Domb
8) Domb
Dixon is before Domb
10
Binary Search Algorithm
4th Iteration
7) Dixon
Middle 1 ( 7 7) 7th
2
Dixon
Found Dixon and it is in the 7th position
11
Binary Search Algorithm
Locate the names
1st Iteration
a) Dixon
b) Davy
Middle 1 ( 1 11) 6th
1) Abbot
2
2) Brown
3) Carr
Daniel
4) Casson
5) Cater
6) Daniel
7) Dixon
8) Domb
Davy is after Daniel
9) Fox
10) Gough
11) Hampton
12
Binary Search Algorithm
2nd Iteration
Middle 1 ( 7 11) 9th
7) Dixon
2
8) Domb
9) Fox
Fox
10) Gough
11) Hampton
Davy is before Fox
3rd Iteration
Middle 1 ( 7 8) 7.5th 8th
2
7) Dixon
Domb
8) Domb
Davy is before Domb
13
Binary Search Algorithm
4th Iteration
7) Dixon
Middle 1 ( 7 7) 7th
2
Dixon
List has expired so Davy is not on the list
14
Binary Search Algorithm
  • The Algorithm proceeds most smoothly when 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.

15
Binary Search Algorithm
  • Questions
  • Locate James in the following lists
  • 1) Andrea 1) Adam
  • 2) Bill 2) Benn
  • 3) Robert 3) James
  • 4) Peter 4) Katie
  • 5) Claire 5) Lou
  • 6) Polly 6) Pamela
  • 7) Nick
  • 8) Caroline
Write a Comment
User Comments (0)
About PowerShow.com