Bin sort is one of the most efficient algorithms, wherein an input vector is split into multiple bins, and then sorting is performed within each bin. The elements are assigned to the bins based on the computations performed on each element. The bins can be a list of multiple vectors or a linked list. The current execution uses a list of multiple vectors as bins. The following R code performs the bin sort operation on a numeric vector (V) containing n elements. The maxValue
variable denotes the element with maximum value within the input vector:
Bin_Sort=function(V,n,maxValue){
bin <-list("binValues"=list(), "nElement"=NA)
## create empty bins
for(i in 1:n){
bin[["binValues"]][[i]]<-NA
bin[["nElement"]][i]<-0
}
## add elements into suitable bins
bin <- addItem(V=V,bin=bin,maxValue=maxValue,n=n)
## bind all bins into a single sorted vector
output <- bindSorted_vec(bin...