Presentation is loading. Please wait.

Presentation is loading. Please wait.

Searching and Sorting Algorithms

Similar presentations


Presentation on theme: "Searching and Sorting Algorithms"— Presentation transcript:

1 Searching and Sorting Algorithms

2 What is an Algorithm? An algorithm is a set of instructions that can be followed to solve a problem.

3 Algorithms You need to understand two search algorithms.
Linear search | Binary search You need to understand three sort algorithms. Bubble sort | Selection sort | Quick sort

4 Searching Algorithms

5 The problem with this method is it isn’t very efficient.
Linear Search Linear search is 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. In this example we are searching for 7. 3 8 1 4 7 6 9 2 12 11 10 5 The problem with this method is it isn’t very efficient.

6 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

7 Exam Question

8 Exam Question

9 Sorting Algorithms

10 Bubble sort is simple to implement but very inefficient.
The bubble sort algorithm works through a list, comparing pairs of values and swapping them if necessary. 3 8 1 4 7 6 Bubble sort is simple to implement but very inefficient.

11 Go to the website and look for the Bubble Sort Activity

12 Selection Sort The selection sort algorithm works through each element in the list to find the smallest element. The smallest element then swaps places with the first element. This process is then repeated with the remaining elements in the list until they are sorted. Pass 1 Pass 3 8 3 1 4 7 6 Pass 4 Pass 2

13 Selection Sort Activity
Go to the website and look for the Selection Sort Activity

14 Quick Sort One of the elements in the list is selected as the pivot and the smaller elements are placed on the left of it and the larger elements are placed to the right. This process is then repeated for the sublists until all elements have been a pivot. 8 3 1 4 7 6 6 4 7 3 1 4 6 8 7 1 8 3 1 4 6 7 8 1 3 3 4 6 7 8

15 Identify the algorithm from its description.
Comparison Activity Identify the algorithm from its description. Description Algorithm Sorts by dividing the list into two halves and works on the appropriate half. Sorts by comparing each pair of adjacent items and swaps them if they are in the wrong order. Searches by dividing the list in two, checks which half the item is in and discards the other half; it keeps dividing and discarding until the item is found. Searches by checking every item one at a time until the appropriate item is found.


Download ppt "Searching and Sorting Algorithms"

Similar presentations


Ads by Google