Before my memory gone, I have to write it down. The following is the sort of Comparion sorrt. Although the time complexity if O(n). However , it is not so useful. It is because it may use up a lot of memory this algorithm. Furthermore, if the elements in an array which needed to be sort were the same as each other. It still cannot gurantee O(n). Also, the range of difference of minimal elements and maxium elements should not larger than elements of the array.
A: an enough large array
B: an array needed to be sort
C: the sorted array of B
A <- 0;
for( i<-0 to B.size - 1 )
A[B[i]] <- A[B[i]] + 1;
j <- 0;
for( i <- 0 to A.size - 1)
if( A[i] > 0 )
C[j++] <- A[i]
The above version is not support any elements of an array A same as each other.
It is still not so useful. It was because it still based on too much assumption....
Tuesday, October 16, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment