Your implementation of mergesort very slow?

25 views
Skip to first unread message

ohman

unread,
Nov 22, 2011, 10:39:46 AM11/22/11
to vogella
Hello, i tried your implementation of mergesort and i noticed it was
very slow if im not wrong. I noticed it when i compared it to my
implementation of insertion sort which was faster even on array sizes
of 500000.

So i found another implementation of mergesort on the internet which
was incredebly much faster and i dont even understand how it can be so
fast. I also tried printing array contents too see if it was correct
and it was. This other implementation of mergesort could sort an array
of 5million elements in only 5seconds, when i tried to sort an array
of 50 000 elements with your implementation of mergesort it took
around 7 seconds. Could you explain this? Is there something wrong
with the other implementation i found or is your code just very slow?

The other implementation i found of mergesort here:

http://www.mycstutorials.com/articles/sorting/mergesort

answers appreciated alot!
//ohman

darrell dupas

unread,
Nov 22, 2011, 2:23:17 PM11/22/11
to vog...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "vogella" group.
> To post to this group, send email to vog...@googlegroups.com.
> To unsubscribe from this group, send email to vogella+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/vogella?hl=en.
>
>

i have found the problem, the problem is the allocation of the helper
array, it is created the size of the initial array over and over,
which made a lot of allocation and deallocation, i have moved the
helper array to also be a class variable and not set to null it each
merge and the performance of vogella's is slightly better than the
mycstutorials, the source code for my modification and test code is
available on my github

https://github.com/semisided1/vogellamergesort

Lars Vogel

unread,
Nov 22, 2011, 3:02:57 PM11/22/11
to vog...@googlegroups.com
Hi Darrel,

cool. Looks great. I update my tutorial soon.

Best regards, Lars

2011/11/22 darrell dupas <dirts...@gmail.com>



--
Lars
http://www.vogella.de - Eclipse, Android and Java Tutorials
http://www.twitter.com/vogella - Lars on Twitter

darrell dupas

unread,
Nov 22, 2011, 3:04:02 PM11/22/11
to vog...@googlegroups.com

no problem

Lars Vogel

unread,
Nov 22, 2011, 3:47:42 PM11/22/11
to vog...@googlegroups.com
Thanks again. Tutorial updated. 
Reply all
Reply to author
Forward
0 new messages