<< Chapter < Page | Chapter >> Page > |
The following discussion is based on the the SIGCSE 2001 paper by Nguyen and Wong, "Design Patterns for Sorting" D. Nguyen and S. Wong, “Design Patterns for Sorting,” SIGCSE Bulletin 33:1, March 2001, 263-267 .
We thus end up with a recursive definition of sorting:
We can see Merritt's recursive notion of sorting as a split-sort-join process in a pictoral manner by considering the general sorting process as a "black box" process that takes an unsorted set and returns a sorted set. Merritt's thesis thus contends that this sorting process can be described as a splitting followed by a sorting of the smaller pieces followed by a joining of the sorted pieces. The smaller sorting process can thus be similarly described. The base case of this recursive process is when the set has been reduced to a single element, upon which the sorting process cannot be broken down any more as it is a trivial no-op.
Merritt's thesis is potentially a very powerful method for studying and understanding sorting. In addition, Merritt's abstract characterization of sorting exhibits much object-oriented (OO) flavor and can be described in terms of OO concepts.
Here, we will restrict ourselves to the process of sorting an array of objects, in-place -- that is, the original array is mutated from unsorted to sorted (as opposed to returning a new array of sorted values and leaving the original untouched). The
Comparator
object used to compare objects will be given to the sorter's constructor.
Here, the invariant process is represented by the concrete
sort
method, which performs the split-sort-sort-join process as described by Merritt. The variant processes are represented by the abstract
split
and
join
methods, whose exact behaviors are indeterminate at this time.
Notification Switch
Would you like to follow the 'Principles of object-oriented programming' conversation and receive update notifications?