Blaginations

An additional opportunity to be hopelessly wrong

Timing n VS n*log(n).

with 2 comments

Standard merge sort is O(n*log(n)), just playing around with some code I did some timing up to the size that all work sorting an array of integers fits in memory. When I drew the results initially I was convinced I had made a mistake, but this really was just b/c I had never quite realized how “linear” n * log(n) looks at these sizes. Here is the graph (red dots are the measured time, blue is a line fitted with the next to last measured value, green is n * log(n) fitted with the next to last measured value).

Merge timing data graphed.

Note that I used to next to last value measured since the last value is a bit of an outlier (I was watching the system monitor, and for some reason the process switched to another core). All code is available in the github repository.

Advertisement

Written by kasterma

May 10, 2011 at 4:11 pm

Posted in Uncategorized

2 Responses

Subscribe to comments with RSS.

  1. That’s pretty great and more convincing than my claim that, in reality, log is bounded by 50.

    Anybody who thinks it’s worthwhile trying to remove a log term from an algorithm also probably thinks that spaghetti sort (http://en.wikipedia.org/wiki/Spaghetti_sort) is linear time. It’s not. Best I can figure, it’s $n^{3/2}$, significantly worse than merge sort.

    Joe Miller

    May 11, 2011 at 12:12 am

  2. Spaghetti sort is a new one on me, the wikipedia analysis certainly leaves to be desired.

    kasterma

    May 11, 2011 at 10:01 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.