ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.