LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2008, 07:57 PM   #1
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
New sorting algorithm (I hope so, anyway)


I came up with an optimization to the Merge Sort algorithm about 2 months ago for my C++ template list library. While I know I sat down and figured it out on my own, I was wondering if it's a duplication of something similar out there. The reason I ask is that it seems entirely too simple of a concept for no one to have come up with it earlier. Of course, I don't imagine many other people sit down to write sorting algorithms.

If you have an interest in data processing algorithms please take a few minutes to check out my work. It's literally a 7-minute read with pictures and everything. It's open-source for those who want to use and abuse it.

The main point-of-interest is its lack of recursion and allocation required by most Merge Sort implementations. You need only create iterators, place markers, and at most 1 temporary element. The page has a link to download a package containing a standalone header.

Please let me know what you think. I don't mind if I actually did waste my time reinventing something that didn't need to be. I just like how the pictures came out


ta0kira
 
Old 02-09-2008, 08:11 PM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Interesting. Only had a quick read, and it's a long time since I did my compsci degree, so don't recall sorting algorithms that well.

I do think your central tenet that people don't sit around and think about sorting algorithms is probably wrong. Back in the "old days" - only tape (or worse still cards) - sorting was a big issue because inefficiency slowed things enormously. These days I'm sure the googles of the world spend plent of time on the issue. As databases get bigger, sorting (and related fields like indexing) remain critical.


Anyway, good luck
 
Old 02-09-2008, 08:20 PM   #3
binutils
Member
 
Registered: Feb 2007
Posts: 59

Rep: Reputation: 15
Hi,
any benchmark result?
 
Old 02-09-2008, 08:48 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Original Poster
Rep: Reputation: Disabled
Nothing official, but (as far as I remember) it kicks the ass off of std::stable_sort and std::sort at -O3 and -O0 but loses slightly at -O1 and -O2. I think that's just a matter of algorithm style and the optimzation rules used by g++. In any case, it's competitive enough with built-ins to be a direct replacement, plus 3 additional features (reverse order, reverse of equal elements, sorting across the end of the array.)

The main reason I use it is to be able to sort across the end of a list for my template library like this, which can be done at the same speed as conventional sorting:
Code:
[ 5 6 3 2 6 7 8 9 1 2 3 4 5 6 7 ] (before)
  end==>|             |start==>
[ 5 6 6 7 6 7 8 9 1 2 2 3 3 4 5 ] (after)
ta0kira
 
Old 02-10-2008, 02:40 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Original Poster
Rep: Reputation: Disabled
Exclamation

(edit: it seems I was grossly mistaken; it has a huge problem I didn't notice before...)
ta0kira

Last edited by ta0kira; 02-10-2008 at 02:52 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bounce Algorithm revof11 Programming 3 05-08-2007 08:50 AM
Algorithm generator phantom_cyph General 6 05-07-2007 09:09 PM
token bucket algorithm vs Leaky bucket algorithm xeon123 Linux - Networking 2 03-26-2007 04:57 AM
Which sorting algorithm? nodger Programming 6 01-28-2005 06:13 PM
huffman algorithm mcshen Programming 3 03-12-2004 02:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration