I am taking an algorithms course online through Coursera, and the first lecture discussed sorting algorithms and after some fighting with the merge code I was able to implement an iterative sorting algorithm (bubble sort) and a recursive sorting algorithm (merge sort).  The purpose of the lecture was to build an appreciation for the variety of solutions possible to even a very simple problem like sorting as well as illustrate the variability in the efficiency of these solutions.  Needless to say I was happy to see that my merge.sort function really was vastly faster than my bubble sort function.  Below is the result of sorting 1000 six digit integers 10 times with each function.

x<-sample size="1000)<o:p">

system.time(replicate(10, bubble.sort(x)))
user                system            elapsed
38.633            0.065             38.856

system.time(replicate(10, merge.sort(x)))
user                system            elapsed
0.374              0.001              0.375

cheers

0

Add a comment

Great Blogs
Great Blogs
About Me
About Me
My Photo
I am broadly interested in the application and development of comparative methods to better understand genome evolution at all scales from nucleotides to chromosomes.
Subscribe
Subscribe
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.