Presentation is loading. Please wait.

Presentation is loading. Please wait.

ALG0183 Algorithms & Data Structures Lecture 12 Taxonomies of Sorting Algorithms 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks taxonomy/flokkunarkerfi.

Similar presentations


Presentation on theme: "ALG0183 Algorithms & Data Structures Lecture 12 Taxonomies of Sorting Algorithms 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks taxonomy/flokkunarkerfi."— Presentation transcript:

1 ALG0183 Algorithms & Data Structures Lecture 12 Taxonomies of Sorting Algorithms 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks taxonomy/flokkunarkerfi Sorting AlgorithmsSorting Algorithms @ YouTube http://www.youtube.com/watch?v=INHF_5RIxTE

2 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 2 case study article “An inverted taxonomy of sorting algorithms” Susan M. Merrit Communications of the ACM, Volume 28, Number 1, (1985), pp 96-99

3 Insertion Sort Items are considered one at a time. Each new item is inserted into the appropriate place relative to the previously sorted items. Having a sorted subarray A[1.. j -1], we insert the single element A[j] into its proper place, yielding the sorted subarray A[1.. j]. Insertion sort is used when sorting a hand of cards. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 3 Traditional Taxonomy due to D.E.Knuth

4 Exchange Sort If two elements are out of order, they are exchanged. The process repeats until all possible comparisons have been made or until no more exchanges are possible. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 4 Traditional Taxonomy due to D.E.Knuth if a[j] > a[j+1] then swap(a[j],a[j+1])

5 Selection Sort The smallest (largest) item is located and separated from the rest. The next smallest (largest) is selected and so on. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 5 Traditional Taxonomy due to D.E.Knuth In the example in the video, additional space is used to perform the sort. Sorting can be done in-place by swapping the least remaining item with the item in the next position to be filled. A sorting algorithm is described as in-place if the sorted items occupy the same storage as the original ones.

6 The focus of Insertion Sort, Exchange Sort, and Selection Sort. “The focus is on an operation on an individual element or pair of elements.” Merrill “The method of choosing the individual element or elements is the key to the algorithm.” Merrill “The algorithm is built by constructing an iteration about the focal operation.” Merrill The focus of the traditional taxonomy is low-level and bottom-up. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 6 Traditional Taxonomy due to D.E.Knuth

7 Merge Sort Two already sorted lists are merged into a single, sorted list. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 7 Traditional Taxonomy due to D.E.Knuth http://www.sparknotes.com/cs/recursion/examples/section3.rhtml

8 Figure 3. The Traditional Taxonomy of Sorting Algorithms ©ACM 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 8

9 An Inverted Taxonomy top-down rather than bottom-up 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 9 Sorting can be viewed as a three-step process: 1.Split the set S to be sorted into parts, say S 1 and S 2. 2.Sort each part, giving S 1 ´ and S 2 ´. 3.Join the parts to produce the sorted set S´. The process has a split procedure and a join procedure.

10 Figure 1. A Top-Down High-Level Sort Process ©ACM 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 10

11 Figure 2. Merge Sort and Quicksort ©ACM 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 11

12 Insertion Sort and Selection Sort What if we do not split into equal-size parts? Suppose set S 2 has only one element, then merge sort collapses into insertion sort, and quicksort collapses into selection sort. Knuth recognised that merging a singleton sequence with an arbitrary sequence is essentially insertion sort. – Neverthless he went ahead and placed these sorts into different categories. Several authors have recognised that quicksort´s worse- case performance occurs when it degrades into selection sort by partitioning a singleton set at each split. – Yet quicksort and selection sort are in different categories in the traditional taxonomy. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 12 singleton/einstaksmengi

13 Exchange Sorts Sinking sort can be seen as an in-place version of insertion sort. Bubble sort can be seen as an in-place version of selection sort. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 13

14 Sinking Sort from Remarks on “A Synthesis of Serving Sorting Algorithms” by John Darlington by David R. Barstow, Acta Informatica 13, 225-227 (1980) © Springer-Verlag 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 14 Input to the right of the ^ and output to the left of the ^.

15 Bubble Sort from Remarks on “A Synthesis of Serving Sorting Algorithms” by John Darlington by David R. Barstow, Acta Informatica 13, 225-227 (1980) © Springer-Verlag 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 15 Input to the left of the ^ and output to the right of the ^.

16 Figure 4. Inverted Taxonomy of Sorting Algorithms ©ACM 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 16

17 What about distributive sorting algorithms? Distributive sorting algorithms do not fit into the inverted taxonomy presented in Figure 4. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 17

18 Figure 6. A logical inverted taxonomy of sorting algorithms Presented in an article with the same title. 8/25/2009 ALG0183 Algorithms & Data Structures by Dr Andy Brooks 18


Download ppt "ALG0183 Algorithms & Data Structures Lecture 12 Taxonomies of Sorting Algorithms 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks taxonomy/flokkunarkerfi."

Similar presentations


Ads by Google