Download presentation
Presentation is loading. Please wait.
Published byBudi Setiabudi Modified over 5 years ago
1
Decision Maths Unit 7 Sorting Algorithms 3. Shell Sort
3
18, , , , , , , 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, , , , , , , 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
4
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, 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, , 5, , 8, 9, ,
5
Writing the list at each step gives
Initial list , 5, , 9, , , , Four sub lists First Pass SORT MERGE 3, 5, , 2, , , ,
6
Two sub lists Second Pass SORT 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
7
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 comparison 1 Swap 5 and 7 1 comparison 0 Swap 12 and 8 1 comparison 1 Swap 9 and comparison 1 Swap
8
3, 8, 18, comparison 0 Swap 3, 8, 18, comparison 0 Swap 3, 8, 18, comparisons 1 Swap 3, 8, 12, 18 5, 2, 7, comparison 1 Swap 2, 5, 7, comparison 0 Swap 2, 5, 7, comparison 0 Swap 2, 5, 7, 9
11
8 / 2 = 4 sub lists First Pass Shuttle Sort C S Merge
12
4 / 2 = 2 sub lists Second Pass Shuttle Sort C S Merge
13
2 / 2 = 1 sub list Third Pass Shuttle Sort C S Total Comparisons and swaps First Pass Second Pass Third Pass Total Comparisons Swaps
15
7 / 2 = 3 sub lists J R E B A I W C S First Pass Shuttle Sort E J R A B I W Merge E J R A B I W
16
3 / 2 = 1 sub list A B I W E J R C S Second Pass Shuttle Sort A B I W E J R A E I J B W R A E I J B W R A E I J B W R A B E I J W R A B E I J W R A B E I J R W Total Comparisons and swaps First Pass Second Pass Total Comparisons Swaps
17
9 / 2 = 4 sub lists First Pass Shuttle Sort C S Merge
18
4 / 2 = 2 sub lists Second Pass Shuttle Sort C S Merge
19
Third Pass Shuttle Sort C S
20
Total Comparisons and swaps
First Pass Second Pass Third Pass Total Comparisons Swaps
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.