Chapter 10
Chapter 10
Chapter 10
Sorting Algorithms
Objectives
• Insertion Sort:
• Keep the cards in your
left hand sorted
• Search algorithms
– Concerned with number of key (item) comparisons
• Sorting algorithms
– Concerned with number of key comparisons and
number of data movements
• Analysis of selection sort
– Function swap
• Number of item assignments: 3(n-1)
– Function minLocation
• Number of key comparisons of O(n2)
FIGURE 10-5 list elements while moving list[4] to its proper place
FIGURE 10-8 list elements while moving list[4] to its proper place
• Function shellSort
– Uses function intervalInsertionSort
• Modified version of insertion sort for array-based lists
• intervalInsertionSort
– Sublist starts at variable begin
– Increment between successive elements given by
variable inc instead of one
• Analysis of Shellsort
– Difficult to obtain