computing ks3 algorithmic thinking: searching and sorting

2
Computing KS3 Algorithmic Thinking: Searching and Sorting Major Concepts Algorithm: a process or set of rules to be followed so that a problem is solved Algorithmic Thinking: defining a computer problem through the steps required Flowchart: a method of showing the steps to solve a problem using symbols Pseudocode: using text to show the steps involved in solving a computing problem. List/Array: A set of data. Can be numerical or text. Searching: a method of logically iterating over a list to find an item. Linear search: a method of finding an item in an unsorted list. Starting at the first item and checking it against the search item until it is found or the end of the list is reached. Binary search: a method of finding an item in a sorted list. Also called ‘Binary chop’, the algorithm splits the list in 2, checks if the search item is the same, less or greater than the middle item. If it is the same, the item is found. If the search item is greater then the middle, the left side of the list is removed, else the right side is removed. Repeated until the item is found or there is only one item left. Sorting: a method of taking an unsorted list and putting it in order Bubble sort: compare two adjacent items. Swap them if the left item is larger than the right item. Repeat until no more comparisons are needed Merge sort: Also called ‘divide and conquer’. Divide the list in two until each item is a separate list. Reassemble, merge, the items comparing the left and right items, swapping as necessary. Continue until the list is reassembled. Linear search efficiency: a poor search method if the list is large as the search item might be at the end of the list. Binary search efficiency: Only useful if the list is order. Good for very large lists – maximum chops on a list of 1000000 is 20! Bubble sort efficiency: good if the list is partially sorted. Worst situation is if all the items are in the wrong order. Merge sort efficiency: it does not matter if the list is partially or not sorted at all. The algorithm will divide the list into separate lists and then reassemble. Use a lot of memory to store the separate lists. Index: Lists and arrays start at 0. EG the list 36892 has index values 0-4 10 Key Questions: 1. What are the two most common search algorithms? 2. Why do we need searching algorithms? 3. Give an example of when you might use either of the two search algorithms 4. Summarise the linear search algorithm in four steps 5. Summarise the binary search algorithm in four steps 6. Give an advantage and disadvantage of binary and serial searching 7. What is the maximum number of divisions using binary search on a list of 512 items? 8. In two lines, state the difference between bubble and merge sort 9. Bubble sort the four cards 10. Merge sort the six cards Challenge Activity : Create a flowchart algorithm of a linear & binary search © March 2019 PiXL Spine Strategy and templates: The PiXL Club Ltd. All rights reserved.

Upload: others

Post on 20-Mar-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computing KS3 Algorithmic Thinking: Searching and Sorting

Computing KS3 Algorithmic Thinking: Searching and Sorting

Major ConceptsAlgorithm: a process or set of rules to be followed so that a problem is solvedAlgorithmic Thinking: defining a computer problem through the steps requiredFlowchart: a method of showing the steps to solve a problem using symbolsPseudocode: using text to show the steps involved in solving a computing problem.List/Array: A set of data. Can be numerical or text. Searching: a method of logically iterating over a list to find an item.Linear search: a method of finding an item in an unsorted list. Starting at the first item and checking it against the search item until it is found or the end of the list is reached.Binary search: a method of finding an item in a sorted list. Also called ‘Binary chop’, the algorithm splits the list in 2, checks if the search item is the same, less or greater than the middle item. If it is the same, the item is found. If the search item is greater then the middle, the left side of the list is removed, else the right side is removed. Repeated until the item is found or there is only one item left.

Sorting: a method of taking an unsorted list and putting it in orderBubble sort: compare two adjacent items. Swap them if the left item is larger than the right item. Repeat until no more comparisons are neededMerge sort: Also called ‘divide and conquer’. Divide the list in two until each item is a separate list. Reassemble, merge, the items comparing the left and right items, swapping as necessary. Continue until the list is reassembled.Linear search efficiency: a poor search method if the list is large as the search item might be at the end of the list.Binary search efficiency: Only useful if the list is order. Good for very large lists – maximum chops on a list of 1000000 is 20!Bubble sort efficiency: good if the list is partially sorted. Worst situation is if all the items are in the wrong order.Merge sort efficiency: it does not matter if the list is partially or not sorted at all. The algorithm will divide the list into separate lists and then reassemble. Use a lot of memory to store the separate lists.Index: Lists and arrays start at 0. EG the list 36892 has index values 0-4

10 Key Questions:1. What are the two most common search algorithms?2. Why do we need searching algorithms?3. Give an example of when you might use either of the two

search algorithms4. Summarise the linear search algorithm in four steps5. Summarise the binary search algorithm in four steps6. Give an advantage and disadvantage of binary and serial

searching7. What is the maximum number of divisions using binary search

on a list of 512 items?8. In two lines, state the difference between bubble and merge

sort9. Bubble sort the four cards

10. Merge sort the six cards

Challenge Activity: Create a flowchart algorithm of a linear & binary search

© March 2019 PiXL Spine Strategy and templates: The PiXL Club Ltd. All rights reserved.

Page 2: Computing KS3 Algorithmic Thinking: Searching and Sorting

Linear Search - Steps• Start at the first item• Compare, repeat until found or end of list reached

is 5 = index 0, 1, 2, 3, 4? Found at index 5

Binary Search - Steps• Find the middle• Compare search item with middle. If larger remove

left hand list

Bubble Sort - Steps

Binary Search –Code

Merge Sort - Steps

Linear Search –Code

KS3 SpineAlgorithmic Thinking: Searching and Sorting

99 2 16 4 5 11 7299 2 16 4 5 11 72

11 16 72 99

16 72 99

72

Find number 11

Find number 72 =3 binary chops

2 99 16 4 5 11 72

2 16 99 4 5 11 72

2 16 4 99 5 11 72

2 16 4 5 99 11 72

2 16 4 5 11 99 72

2 16 4 5 11 72 99

First Pass

B D I F W A X

B D I F W A X

B D I F W A X

B D I F W A X

B D F I A W X

B D F 1 A W X

A B D F I W X

Bubble Sort –Code

© March 2019 PiXL Spine Strategy and templates: The PiXL Club Ltd. All rights reserved.