bucket sort

3
Bucket Sort Bucket sort is possibly the simplest distribution sorting algorithm. The essential requirement is that the size of the universe from which the elements to be sorted are drawn is a small, fixed constant, say m. For example, suppose that we are sorting elements drawn from , i.e., the set of integers in the interval [0,m-1]. Bucket sort uses m counters. The counter keeps track of the number of occurrences of the element of the universe. Following figure illustrates how this is done. In the figure above, the universal set is assumed to be {0, 1, . . ., 9}. Therefore, ten counters are required-one to keep track of the number of zeroes, one to keep track of the number of ones, and so on. A single pass through the data suffices to count all of the elements. Once the counts have been determined, the sorted sequence is easily obtained. E.g., the sorted sequence contains no zeroes, two ones, one two, and so on. Mmcc Computer Centre, 38 Burkit Road, T.Nagar, Chennai-17 24323605, 9444037410 document.doc Page 1 of 3

Upload: krystos-light

Post on 17-Aug-2015

3 views

Category:

Documents


2 download

DESCRIPTION

coding

TRANSCRIPT

Bucket SortBucket sort is possibly the simplest distribution sorting algorithm. The essentialrequirement is that the size of the universe from which the elements to be sorted aredrawn is a small, fixed constant, say m. or example, suppose that we are sorting elements drawn from , i.e., the set of integersin the interval!",m#$%. Bucket sort uses m counters. The counter keeps track of thenumber of occurrences of theelement of the universe. ollowing figureillustrates howthis is done. &n the figure above, the universalset is assumed to be '", $, . . ., (). Therefore, tencounters are required#one to keep track of the number of zeroes, one to keep track ofthe number of ones, and so on. * single pass through the data suffices to count all ofthe elements. +nce the counts have been determined, the sorted sequence is easilyobtained. ,.g., the sorted sequence contains no zeroes, two ones, one two, and so on.Example :-mcc .omputer .entre, /0 Burkit 1oad, T.2agar, .hennai#$3 45/4/6"7, (555"/35$" 43(/$0703.doc8age 1 of 2main9:'int i;int a!$"% < '/,$,5,$,7,(,4,6,7,5);clrscr9:;printf9=>n>n>n=:;BucketSort9a,$":;printf9=>n>n>n>n>n=:;for9in>n=:;for9i