Decision Maths Unit 7 Sorting Algorithms 3. Shell Sort.

Slides:



Advertisements
Similar presentations
Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 Bubblesort compares the numbers in pairs from left to right exchanging.
Advertisements

Early Math OrdinalandCardinalNumbers. Ordinal Numbers Early Math Move one.
Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set. 2.Compare the first two elements,
Ordinal Numbers. Order 1,2,3,4,5,6,7,8 These numbers are in order. 1,2,4,6,5,8,7 These numbers are not in order.
10 Little Gifts First one for you health Second for you luck.
Let’s repeat the ordinal numbers!
Type Title Here for Tic-Tac-Toe Type names of students in group here.
Cut Scores Comparison: Reading WKCE Reading Scale Score by Grade Performance Level Advanced Proficient
Title Sub Head. Title ► First level information  Second level information Third level information +Fourth level information ◦Fifth level information.
Balanced Parentheses G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\}
Ordinal Numbers. Table of Ordinal Numbers Ordinal Numbers from 1 through 1,000,000 1stfirst11theleventh21sttwenty-first31stthirty-first 2ndsecond12thtwelfth22ndtwenty-second40thfortieth.
Behaviour.
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun. Mercury is the eighth largest planet. Mercury.
(Made by Du) (Made by Du) Take a Challenge! `  1. Two 1. Two 1. Two   2. Four 2. Four2. Four   3. One 3. One3. One.
have breakfast have a break learn Maths speak English draw pictures read a tale write words sing songs listen to the teacher play computer.
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.
To know and use the Bubble Sort and Shuttle Sort Algorithms.
1 Introduction to Sorting Algorithms Sort: arrange values into an order Alphabetical Ascending numeric Descending numeric Two algorithms considered here.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
Bubble Sort Example
Multiplying Common Fractions Multiplying next Using the Corn Bread © Math As A Second Language All Rights Reserved.
SORTING ALGORITHMS King Saud University College of Applied studies and Community Service CSC 1101 By: Nada Alhirabi 1.
Sorting Sorting takes an unordered array and makes it an ordered one
Guitar Chords. G First finger 2nd fret, 5 th string. Second finger 3 rd fret, 6 th string. Third finger 3 rd fret, 1 st string.
What's the next number? 10,20,30,40…10,20,30,40… 40,50,60,70…40,50,60,70… 35,45,55,65…35,45,55,65… 21,32,43,54…21,32,43,54… 100,90,80,70…100,90,80,70…
Example 1 Writing Powers Write the product as a power and describe it in words. a. 44= to the second power, or 4 squared 9 to the third power,
In the first pass, the first two numbers are compared. The shuttle sort compares the numbers in pairs from left to right exchanging when necessary.
Merge Sort Comparison Left Half Data Movement Right Half Sorted.
Fractions Part Two. How many halves are in a whole? 2 1/2.
MAP Mathematics Spring 2015 % Proficient and Advanced.
State Data Comparisons FY12, FY13, FY14. CRCT – Third Grade Grade 3 JDES 2012 State 2012 JDES 2013 State 2013 JDES 2014 State 2014 Reading
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun.
Cardinal versus ordinal numbers
Zoom In Game.
Adding Like Fractions Adding Like Fractions
Which fraction does correspond to the coloured part?
Use the Binomial Theorem
Use the Binomial Theorem
Unit 4 Big or small? Lesson 3 Part B : My class.
3.3 Fundamentals of data representation
Math Flash Fractions II
Use the Binomial Theorem
Shuttle Sort Example 1st pass Comparisons: 1
Mona Lisa Project Using Image Blender to change this famous portrait in four different ways Created by:
And now for something completely different . . .
Student #7 starts with Locker 7 and changes every seventh door
Bin packing – First fit algorithm
Math Flash Fractions II
Math Flash Fractions II
Linear sequences A linear sequence is a name for a list of numbers where the next number is found by adding or subtracting a constant number. Here is an.
Bubble Sort Example 9, 6, 2, 12, 11, 9, 3, 7 6, 9, 2, 12, 11, 9, 3, 7 Bubblesort compares the numbers in pairs from left to right exchanging.
Shell Sort and Merge Sort
Who is the winner ?.
AS Maths Decision Paper January 2010 Model Answers.
Sorting Example Bubble Sort
Ms. Lindsey’s Kindergarten Class 11/1/16
Which fraction does correspond to the coloured part?
How to find the nth rule for a linear sequence
MATH 1310 Section 4.1.
Our birthdays 3B:Unit 3.
The Solar System.
Shuttle Sort Example 1st pass Comparisons: 1
Math Flash Fractions II
The Solar System.
Ordinal Numbers.
Ordinal Numbers.
Math Flash Fractions II
MATH 1310 Section 4.1.
Math Flash Fractions II
MATH 1310 Section 4.1.
Presentation transcript:

Decision Maths Unit 7 Sorting Algorithms 3. Shell Sort

18, 5, 12, 9, 3, 7, 8, 2 As there are 8 numbers there will be 8 ÷ 2 = 4 sub lists The first and fifth number 18 and 3 The second and sixth number 5 and 7 The third and seventh number 12 and 8 The fourth and eighth number 9 and 2 Shuttle sort and merge of these pairs of numbers gives 3, 5, 8, 2, 18, 7, 12, 9 On the first pass there were 4 sub lists, so on the second pass there will be 4 ÷ 2 = 2 sub lists The first sub list contains the 1st, 3rd, 5th and 7th numbers The second sub list contains the 2nd 4th , 6th and 8th numbers

The first sub list contains the 1st, 3rd, 5th and 7th numbers 3, 8, 18, 12 The second sub list contains the 2nd 4th , 6th and 8th numbers 5, 2, 7, 9 The two lists are shuttle sorted and merged again to give 3, 2, 8, 5, 12, 7, 18, 9 There were 2 sub lists in the second pass, so in the third pass there will be 2 ÷ 2 = 1 sub list. This last list is now shuttle sorted. 2, 3, 5, 7, 8, 9, 12, 18

Writing the list at each step gives Initial list 18, 5, 12, 9, 3, 7, 8, 2 Four sub lists 18 3 5 7 12 8 9 2 3 18 First Pass 5 7 SORT 8 12 2 9 MERGE 3, 5, 8, 2, 18, 7, 12, 9

Two sub lists 3 8 18 12 5 2 7 9 Second Pass 3 8 12 18 SORT 2 5 7 9 MERGE 3, 2, 8, 5, 12, 7, 18, 9 One sub list 3, 2, 8, 5, 12, 7, 18, 9 Third Pass SORT 2, 3, 5, 7, 8, 9, 12, 18

Pass Comparisons Swaps 1st 4 3 2nd 7 2 3rd 12 6 Total 23 11 In the first pass, there were 4 comparisons and 3 swaps 18 and 3 1 comparison 1 Swap 5 and 7 1 comparison 0 Swap 12 and 8 1 comparison 1 Swap 9 and 2 1 comparison 1 Swap

3, 8, 18, 12 1 comparison 0 Swap 3, 8, 18, 12 1 comparison 0 Swap 3, 8, 18, 12 2 comparisons 1 Swap 3, 8, 12, 18 5, 2, 7, 9 1 comparison 1 Swap 2, 5, 7, 9 1 comparison 0 Swap 2, 5, 7, 9 1 comparison 0 Swap 2, 5, 7, 9

8 / 2 = 4 sub lists 32 11 3 27 16 9 23 19 32 16 11 9 3 23 27 19 First Pass Shuttle Sort C S 1 1 16 32 9 11 1 1 3 23 1 0 19 27 Merge 1 1 19 27 9 11 3 23 16 32 4 3

4 / 2 = 2 sub lists 16 9 3 19 32 11 23 27 16 3 32 23 9 19 11 27 Second Pass Shuttle Sort C S 4 2 3 16 23 32 9 11 19 27 4 1 Merge 3 16 23 32 9 11 19 27 8 3

2 / 2 = 1 sub list Third Pass Shuttle Sort C S 1 0 3 9 16 11 23 19 32 27 3 9 16 11 23 19 32 27 1 0 3 9 16 11 23 19 32 27 2 1 3 9 11 16 23 19 32 27 1 0 3 9 11 16 23 19 32 27 2 1 3 9 11 16 19 23 32 27 1 0 3 9 11 16 19 23 32 27 2 1 3 9 11 16 19 23 27 32 10 3 Total Comparisons and swaps First Pass Second Pass Third Pass Total Comparisons 4 8 10 22 Swaps 3 3 3 9

7 / 2 = 3 sub lists J R E B A I W C S 3 2 First Pass Shuttle Sort E J R 1 1 A B I W 1 0 Merge E J R A B I W 5 3

3 / 2 = 1 sub list A B I W E J R C S 1 1 Second Pass Shuttle Sort A B I W E J R A E I J B W R 1 0 A E I J B W R 1 0 A E I J B W R 4 3 A B E I J W R 1 0 A B E I J W R 2 1 A B E I J R W 10 5 Total Comparisons and swaps First Pass Second Pass Total Comparisons 5 10 15 Swaps 3 5 8

9 / 2 = 4 sub lists 18 3 45 17 1 26 43 22 16 18 1 16 3 26 45 43 First Pass Shuttle Sort 17 22 C S 3 2 1 16 18 3 26 1 0 43 45 1 1 22 17 1 1 Merge 22 17 1 16 18 43 45 3 26 6 4

4 / 2 = 2 sub lists 1 3 43 22 16 26 45 17 18 1 43 16 45 18 3 22 26 17 Second Pass Shuttle Sort C S 7 3 1 16 18 43 45 3 17 22 26 5 2 Merge 1 16 18 43 45 3 17 22 26 12 5

Third Pass Shuttle Sort C S 1 0 1 3 16 17 18 22 43 26 45 1 3 16 17 18 22 43 26 45 1 0 1 3 16 17 18 22 43 26 45 1 0 1 3 16 17 18 22 43 26 45 1 0 1 3 16 17 18 22 43 26 45 1 0 1 3 16 17 18 22 43 26 45 1 0 1 3 16 17 18 22 43 26 45 2 1 1 3 16 17 18 22 26 43 45 1 0 1 3 16 17 18 22 26 43 45 9 1

Total Comparisons and swaps First Pass Second Pass Third Pass Total Comparisons 6 12 9 27 Swaps 4 5 1 10