Download presentation
Presentation is loading. Please wait.
1
Design Patterns For Sorting
Lauren Schmidt
2
Knuth Three Sorting Taxonomies
Insertion Items inserted right where they need to go Selection Smallest located first, then next item, etc Exchange Items swapped when found out of order Algorithms based on how items are chosen More complicated algorithms try to optimize these three
3
Recursive notion of sorting Top-down approach
Merritt’s Thesis All comparison based sorting can be seen as a “Divide and Conquer” Algorithm split into two groups: Hard split/easy join – Merge sort Easy split/hard join – Quick sort Recursive notion of sorting Top-down approach
4
SORTING WITH MERRITT’s Thesis
Start with an unsorted pile (blue) Red dashes represent the “black box” where sorting happens After going into the black box, the pile is sorted (yellow)
5
SPLIT Unsorted pile is split into multiple unsorted piles
6
SORT Smaller unsorted piles can continue to be split and sorted Base case reached when single element in pile
7
JOIN Sorted piles are then joined into a single sorted pile
8
Why do we care? We can describe using OO concepts!
Which sorting processes are invariant? Split into subpiles Sort subpiles Join subpiles Which sorting processes are variant? Algorithm to split Algorithm to sort Algorithm to join
9
Some constraints Sorting arrays in place Given a comparator to compare objects in array
10
Design patterns for sorting
Template method pattern Captures abstract sort procedure Strategy pattern Decouple sort from comparison Decorator design pattern Makes design flexible/extensible
11
Union design pattern to capture invariant processes
Template method Union design pattern to capture invariant processes Split Join Template design pattern to capture invariant sort process
12
Strategy pattern for object comparison
Sorting and comparing objects decoupled from one another ASorter maintains reference to Aorder Reuse of same sorting strategies and/or ordering schemes for different algorithms
13
Decorator pattern for analysis
Add on performance analysis without changing previously described architecture
14
Easier to analyze complexity of more complicated sorting algorithms
What do we gain? Extensibility – can easily piece together join and sort strategies to construct different sorting algorithms Easier to analyze complexity of more complicated sorting algorithms Wong & Dung suggest for educational purposes OO Design introduction + sorting algorithms!
15
What do we lose? Overhead causes runtime performance to take a hit
16
SOurces Connextions Module: Design Patterns for Sorting Nguyen, Wong. Design Patterns for Sorting (2001). Merritt, S. An Inverted Taxonomy of Sorting Algorithms, Comm. ACM, 28, 1 (Jan. 1985),
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.