Sorting Algorithms 2.1 – Algorithms Thursday, 26

Published  . 0 views
↓ Download
Sorting Algorithms 2.1 – Algorithms Thursday, 26
1 / 1
Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 1 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 2 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 3 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 4 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 5 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 6 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 7 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 8 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 9 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 10 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 11 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 12 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 13 of 14 Sorting Algorithms 2.1 – Algorithms Thursday, 26 - slide 14 of 14
Description: Sorting Algorithms 2.1 Algorithms Thursday, 26 April 2018 Sorting Algorithms Learning Objective: To be able to demonstrate an understanding of standard sorting algorithms. Success Criteria: I can describe how items are sorted using a

Related Topics

Download Presentation

"Sorting Algorithms 2.1 – Algorithms Thursday, 26" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

slide1. Sorting Algorithms 2.1 – Algorithms<br>
slide2. Thursday, 26 April 2018 Sorting Algorithms Learning Objective: To be able to demonstrate an understanding of standard sorting algorithms.

Success Criteria:
I can describe how items are sorted using a bubble sort algorithm.
I can write a bubble sort algorithm.
I can describe how items are sorted using an insertion sort algorithm.
I can write an insertion sort algorithm. Unit 2: Computational Thinking, Algorithms & Programming<br>
slide3. Sorting Algorithms You need to know how to complete the following sort algorithms:
Bubble sort
Insertion sort
Merge sort Unit 2: Computational Thinking, Algorithms & Programming<br>
slide4. Bubble Sort A bubble sort works by comparing each item in the list to the item to the right of it. The item is then moved based upon whether it is bigger/smaller. Unit 2: Computational Thinking, Algorithms & Programming 10 2 11 6 5 Step 1: Compare the first two numbers. Are they in order? Adjust them if not. Step 2: 2 10 11 6 5 Move to the next two numbers. Are they in order? Adjust them if not.<br>
slide5. Bubble Sort … Unit 2: Computational Thinking, Algorithms & Programming Step 3: Move to the next two numbers. Are they in order? Adjust them if not. Step 4: 2 6 11 10 5 Move to the next two numbers. Are they in order? Adjust them if not 2 6 11 5 10 Step 5: Once you have been through the entire list, check that they are in order. If they are, great! If not, undertake the same process again until they are in order.<br>
slide6. Bubble Sort: Activity Task: Sort the above using the bubble sort algorithm. Show your steps. Show the order of the list after each adjustment. Unit 2: Computational Thinking, Algorithms & Programming 15 9 22 27 14 44 30 16 51 27 A B Pear Banana Apple Blueberry Pineapple C Rain Lolly Freedom Aeroplane Zebra D<br>
slide7. Insertion Sort Algorithm The insertion sort works by looking at each value in turn and inserting the value into its correct place in the list. Unit 2: Computational Thinking, Algorithms & Programming 9 2 5 8 7 Step 1: Compare the first two items. 9 > 2 so 2 moves position.<br>
slide8. Insertion Sort Algorithm Unit 2: Computational Thinking, Algorithms & Programming 2 5 9 8 7 Step 2: Insert 5 into its correct position. 5 > 2 and 5 < 8 so 5 moves position. Step 3: Insert 8 into its correct position. 8 > 5 and < 9 so 8 moves position. 2 8 5 9 7<br>
slide9. Insertion Sort Algorithm Unit 2: Computational Thinking, Algorithms & Programming Step 4: Insert 7 into its correct position. 7 > 5 and 7 < 8 so 7 moves position. 2 7 5 8 9 2 5 7 8 9 Completed Insertion Sort:<br>
slide10. Insertion Sort: Activity Task: Sort the above using the Insertion sort algorithm. Show your steps. Show the order of the list after each adjustment. Unit 2: Computational Thinking, Algorithms & Programming 4 2 8 9 7 19 5 8 7 15 A B C 40 9 32 27 20<br>
slide11. Merge Sort Algorithm The merge sort algorithm is an example of a divide-and-conquer algorithm and takes advantage of two facts:

Small lists are easier to sort than large lists.
It’s easier to merge two-ordered lists than two unordered lists. Unit 2: Computational Thinking, Algorithms & Programming Split the list in half (the smaller lists are called sub-lists) – the second sub-list should start at the middle item.
Keep repeating step 1 on each sub-list until all the lists only contain one item.
Merge pairs of sub-lists so that each sub-list has twice as many items. Each time you merge sub-lists, sort the items into the right order.
Repeat step 3 until you’ve merged all the sub-lists together.<br>
slide12. Merge Sort: Example Unit 2: Computational Thinking, Algorithms & Programming F P A L T D K H T D K H F P A L K H T D A L F P F P A L T D K H F P A L D T H K A F L P D H K T A D F H K L P T<br>
slide13. Merge Sort Pros & Cons The pros and cons of merge sort algorithms are as follows: Unit 2: Computational Thinking, Algorithms & Programming<br>
slide14. Merge Sort: Activity Task: Sort these items using the merge sort method. Unit 2: Computational Thinking, Algorithms & Programming S A P H J Z E R 19 5 29 1 87 14 61 33 Dog Bird Turtle Horse Snake Goat Lion Bear<br>