How are there so many sorting algorithms?

Click For Summary
The discussion centers on the abundance of sorting algorithms and whether there is a limit to the number of algorithms for sorting, a seemingly simple problem. It is noted that while there are many sorting techniques, such as selection sort, heap sort, quick sort, merge sort, and insertion sort, the number of possible algorithms is theoretically infinite. This is because algorithms can be modified or combined in countless ways, even if the fundamental approach remains the same. The conversation highlights that different sorting algorithms have unique advantages and disadvantages, often influenced by the type of data being sorted. Furthermore, the most common algorithms in compiler libraries are variations of quick sort and merge sort, with specific implementations for maintaining order in certain data structures. Ultimately, the consensus is that there is no practical limit to the number of sorting algorithms, as new techniques can always be devised or existing ones altered.
Avichal
Messages
294
Reaction score
0
I was looking through the list of sorting algorithms and there are so many of them! A simple problem where each element is less that or greater than the next term has so many solutions. How is that?

My question is a rhetorical one but is there any limit to number of different techniques for sorting?
Till now the algorithms I have read do the following:-
Selection sort: Finds the minimum and places in the first position and so on
Heap sort: Finds the minimum but in an efficient way using binary trees
Quick sort and Merge sort: Use divide and conquer
Insertion sort: Finds the correct position and places element there

Surely there is a limit to number of different techniques for sorting, right?
 
Technology news on Phys.org
Unless you specify some strict criteria for admissible sorting algorithms, there are infinitely many of them.
 
We study so many different sorting algorithms because they have different combinations of advantages and disadvantages, which often depend on the kind of data being sorted.
 
Some of the sort algorithms were developed before similar but faster algorithms were discovered, and some are mostly educational and don't offer any significant advantages. As an example of the latter, top down merge sort recursively splits an array into two until repeated recursion produces arrays of size 1, by generating indices stored on the stack during recursion, at which point the merge process begins and flows back up the call chain. Bottom up merge sort skips the unneeded recursive process and just starts off by considering an array of size n to be n arrays of size 1, and uses iteration to generate indices as needed during the merge process.

The most common sort algorithms found in compiler libraries are variations of quick sort and merge sort. Microsoft / HP C++ Standard Template Library uses quick sort for array / vector types if the original order for equal elements does not need to be preserved called std::sort(), and merge sort if the original order needs to be preserved called std::stable_sort(), and also uses merge sort and an array of list structures (the head and tail pointers) for sorting linked lists called std::list::sort().

Non-comparason sorts like radix sort are fastest if sorting a large array of 4 to 16 byte integers or something similar where the length of the data that determines the sort order is relatively small.
 
I am not asking why we have so many sorting algorithms.
I'm asking whether there is a limit to number of algorithms to such a simple problem?

I guess my question can be generalized as follows:- Given a problem, is there a limit to number of algorithms to the problem.

While for a complicated problem, there might be infinitely many solutions but in this case i.e. sorting is there a limit? What else can you do to sort apart from the known algorithms?
 
Avichal said:
I'm asking whether there is a limit to number of algorithms to such a simple problem?

You were given an answer to this.

I guess my question can be generalized as follows:- Given a problem, is there a limit to number of algorithms to the problem.

Obviously not. If you have an algorithm that produces at least one bit, you can add a step that flips that bit, and another step that flips it back. The result is the same as in the original algorithm. You can add infinitely many steps like that, getting infinitely many algorithms.
 
voko said:
Obviously not. If you have an algorithm that produces at least one bit, you can add a step that flips that bit, and another step that flips it back. The result is the same as in the original algorithm. You can add infinitely many steps like that, getting infinitely many algorithms.

Ah, I didn't think this in such detail. Probably I should ask whether there are infinitely many ideas or techniques to sort? Anyways, I guess there are indeed infinitely many ways to sort.
Also since there is no way to count number of solutions to a problem, the question is meaningless.
 
their is a 4 volume book called The art of algorithms, flip through it sometime.
 
The Art of Computer Programming I mean,lol
 
  • #10
Perhaps a visualization will help.

https://www.youtube.com/watch?v=kPRA0W1kECg
 
  • #11
Cool video!
Anyways I don't have any trouble understanding the algorithms. I was only interested if there is a limit to the number of algorithms
 

Similar threads

Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K