Bin sort and radix sort
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 ...
Get R Data Structures and Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.