sorting

sorting - Elementary Sorting Algorithms Many of the slides...

This preview shows pages 1–7. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the 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 non-decreasing order K p 1 < … < K p n . Permutation : a one-to-one 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) Comparison-based 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 Array-based (consecutive keys are stored in consecutive memory locations) vs. List-based sort (may be stored in nonconsecutive locations in a linked manner) In-place 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

{[ snackBarMessage ]}

Page1 / 26

sorting - Elementary Sorting Algorithms Many of the slides...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online