Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching Computing to GCSE

Similar presentations


Presentation on theme: "Teaching Computing to GCSE"— Presentation transcript:

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

2 Specification Content
OCR Standard searching algorithms: Binary search Linear search AQA Understand and explain how the linear search algorithm works. Understand and 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.

3 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

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

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

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

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

8 Tracing a Binary Search
In an exam the students could be asked to show how 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

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

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


Download ppt "Teaching Computing to GCSE"

Similar presentations


Ads by Google