Teaching Computing to GCSE Session 6 Theory Searching

  • Slides: 10
Download presentation
Teaching Computing to GCSE Session 6 Theory: Searching Algorithms Practical: Exception Handling and Debugging

Teaching Computing to GCSE Session 6 Theory: Searching Algorithms Practical: Exception Handling and Debugging

Specification Content OCR • Standard searching algorithms: • Binary search • Linear search AQA

Specification Content OCR • Standard searching algorithms: • Binary search • Linear search AQA • Understand explain how the linear search algorithm works. • Understand explain how the binary search algorithm works. • Compare and contrast linear and binary search algorithms. Edexcel • Understand how standard algorithms (linear search, binary search) work.

Linear Search Algorithm This is the simplest search algorithm, it works by checking each

Linear Search Algorithm This is the simplest search algorithm, it works by checking each element in the list in turn until the required value is found. In this example we are looking for the value 7: 6 2 1 4 7 9

index = 0 Activity 1 search. Value = 4 1. Place these lines of

index = 0 Activity 1 search. Value = 4 1. Place these lines of pseudocode to recreate the linear search algorithm. 2. Implement the algorithm in Python. if values[index] == search. Value then endwhile array values = [6, 2, 1, 4, 7] index = index + 1 array. Len = values. length while found == false and index < array. Len print(“Found at index “+index) found = true endif found = false

Binary Search Algorithm The binary search algorithm is used to search sorted lists. It

Binary Search Algorithm The binary search algorithm is used to search sorted lists. It starts by finding the mid point and comparing it to the required value. If the value is greater than the midpoint, the left hand side of the list is discarded. If the value is lower than the midpoint, the right hand side of the list is discarded. This process is repeated until the value is found.

Activity 2 This activity will demonstrate a fun way of teaching searching algorithms.

Activity 2 This activity will demonstrate a fun way of teaching searching algorithms.

Activity 3 Compare and contrast the linear and binary search algorithms using this table:

Activity 3 Compare and contrast the linear and binary search algorithms using this table: Algorithm Linear Search Binary Search Advantages Disadvantages

Tracing a Binary Search In an exam the students could be asked to show

Tracing a Binary Search In an exam the students could be asked to show the binary search algorithm could be used to search for a particular value in a list. In this example we are looking for 7. 1 2 3 4 5 6 7 8 7 8 ↑ ↑ ↑

Activity 4 Show the value 8 would be found in the list below: 1

Activity 4 Show the value 8 would be found in the list below: 1 2 4 8 16 ↑ 1 2 4 8 ↑ ↑ 8 ↑ 32 64 128 256

Break After the break we will look at exception handling and debugging.

Break After the break we will look at exception handling and debugging.