This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Elementary Sorting Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill Sorting – Definitions Input: n records , R 1 … R n , from a file . Each record R i has a key K i possibly other (satellite) information The keys must have an ordering relation that satisfies the following properties: Trichotomy : For any two keys a and b , exactly one of a b , a = b , or a b is true. Transitivity : For any three keys a , b , and c , if a b and b c , then a c. The relation = is a total ordering ( linear ordering ) on keys. l l Sorting – Definitions Sorting : determine a permutation Π = ( p 1 , … , p n ) of n records that puts the keys in nondecreasing order K p 1 < … < K p n . Permutation : a onetoone function from {1, …, n } onto itself. There are n ! distinct permutations of n items. Rank : Given a collection of n keys, the rank of a key is the number of keys that precede it. That is, rank ( K j ) =  { K i  K i < K j } . If the keys are distinct, then the rank of a key gives its position in the output file. Sorting Terminology Internal (the file is stored in main memory and can be randomly accessed) vs. External (the file is stored in secondary memory & can be accessed sequentially only) Comparisonbased sort : uses only the relation among keys, not any special property of the representation of the keys themselves. Stable sort : records with equal keys retain their original relative order; i.e., i < j & Kp i = Kp j ⇒ p i < p j Arraybased (consecutive keys are stored in consecutive memory locations) vs. Listbased sort (may be stored in nonconsecutive locations in a linked manner) Inplace sort : needs only a constant amount of extra space in addition to that needed to store keys. Sorting Categories Sorting by Insertion insertion sort, shellsort Sorting by Exchange bubble sort, quicksort Sorting by Selection selection sort, heapsort Sorting by Merging merge sort Sorting by Distribution radix sort Elementary Sorting Methods Easier to understand the basic mechanisms of sorting....
View
Full Document
 Fall '08
 STAFF
 Algorithms, Sort, Insertion Sort, Shell, Donald Shell

Click to edit the document details