Presentation is loading. Please wait.

Presentation is loading. Please wait.

WJEC GCSE Computer Science

Similar presentations


Presentation on theme: "WJEC GCSE Computer Science"— Presentation transcript:

1 WJEC GCSE Computer Science
Unit 2 Searching and Sorting

2 Learning Intentions and Outcomes
Explain and use linear and binary search algorithms. Describe the characteristics of merge sort and bubble sort algorithms. Developing Explain how linear and binary search algorithms work Follow linear and binary search algorithms to identify if an item is found in a list Describe how the merge sort algorithm works Describe how the bubble sort algorithm works Secure Demonstrate a bubble sort algorithm on a set of data Demonstrate a merge sort algorithm on a set of data

3 Linear Search Linear search is the simplest searching algorithm; it starts at the first element in the list and checks every element until it finds the one it is looking for. LIST = Let’s search for 7: SEARCH = 7 FOR i in range(LIST): if LIST[i] == SEARCH: RETURN “Found” 3 8 1 4 7 6 9 2 12 11 10 5

4 Binary Search Binary search is a good way of searching lists that have been sorted. At each step it halves the number of items it needs to look at. In this example we are going to search for 14. 1 2 4 5 6 8 10 12 13 14 15 1 FUNCTION BSearch(List, ItemToFind, Min, Max) Variable Value Min Max MidPoint 2 MidPoint = (Min + ((Max – Min / 2)) 6 3 IF List[MidPoint] < ItemToFind THEN (10-5) 5 9 11 4 Bsearch(List, ItemToFind, MidPoint+1, Max) 10 8 5 5 ELSE IF List[MidPoint] > ItemToFind THEN Return Value 10 6 Bsearch(List, ItemToFind, Min, MidPoint-1) 7 ELSE 8 RETURN MidPoint 9 END IF 9 END FUNCTION

5 Comparing Linear and Binary Search

6 Bubble Sort

7 Bubble Sort One “Pass” of the Bubble Sort Algorithm A “Pass” is an iteration over the entire unsorted section of the array.

8 Merge Sort

9 Workbook Complete section 10 Q1-4


Download ppt "WJEC GCSE Computer Science"

Similar presentations


Ads by Google