RadixSort - Radish-Sort 4/1/2003 8:54 AM Bucket-Sort...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Bucket-Sort and Radix-Sort 1 Bucket-Sort and Radix-Sort 0 1 2 3 4 5 6 7 8 9 B 1, c 7, d 7, g 3, b 3, a 7, e ∅∅∅ ∅∅ Bucket-Sort and Radix-Sort 2 Bucket-Sort (§10.5.1) Let be S be a sequence of n (key, element) items with keys in the range [0, N 1] Bucket-sort uses the keys as indices into an auxiliary array B of sequences (buckets) Phase 1 : Empty sequence S by moving each item ( k , o ) into its bucket B [ k ] Phase 2 : For i = 0, , N 1 , move the items of bucket B [ i ] to the end of sequence S Analysis: ± Phase 1 takes O ( n ) time ± Phase 2 takes O ( n + N ) time Bucket-sort takes O ( n + N ) time Algorithm bucketSort ( S, N ) Input sequence S of (key, element) items with keys in the range [0, N 1] Output sequence S sorted by increasing keys B array of N empty sequences while ¬ S.isEmpty () f S.first () ( k , o ) S.remove ( f ) B [ k ] .insertLast (( k , o )) for i 0 to N 1 while ¬ B [ i ] .isEmpty () f B [ i ] .first () ( k , o ) B [ i ] .remove ( f ) S.insertLast (( k , o )) Bucket-Sort and Radix-Sort 3 Example Key range [0, 9] 7, d 1, c 3, a 7, g 3, b 7, e 1, c 3, a 3, b 7, d 7, g 7, e Phase 1 Phase 2 0 1 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 2

RadixSort - Radish-Sort 4/1/2003 8:54 AM Bucket-Sort...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online