Binary search tree pros cons
Sorting a list of items is a major topic that I can't even begin to deal with here thick books have been written on the subject.
I'm just going to mention a few sorting algorithms and their characteristics. The first class shouldn't be used for sorting really big arrays, say bigger than there is no real limit; it depends on your time constraints.
Trees — CS Algorithms and Data Structures documentation
However they are usually very quick to code and debug, so always consider using them unless you are sure that they won't cut it. The algorithms in the second class are very seldom O n 2 , so it is fine to use them in most applications, particularly in computer olympiads where you only have 5 or 10 test cases and are highly unlikely to get a really slow case, and even if you do you only lose some of your points.
These algorithms can actually be faster than those in the third class because they are simpler. Each of the sorts below has a description of the algorithm, the efficiency, pros and cons and other notes. If the middle element in the array is very large or very small, the sort becomes slower.
To reduce the chances of this, you can take median of the first, middle and last elements and put it in the middle. In a degenerate case, Quick sort could also recurse to a very deep level and cause a stack overflow.
One way to avoid this is to keep track of the level of recursion e.
This isn't an especially useful sort, but the running time is guaranteed O n. Also, if you have already implemented a heap for some other reason, then this sort comes almost for free.
Linked Lists Vs Binary Search Tree
It is possible to get some extra speed by constructing the heap in one pass: This makes the heap creation take linear time. It is convenient to sort the right half backwards, and have the pointer to the second half move backwards.
data structures - Advantages of Binary Search Trees over Hash Tables - Stack Overflow
Then you never have to check whether either list is empty; the pointer simply moves to the biggest element in the other and is never used again. I used to like this sort because it is guaranteed O n. Last updated Sun Nov 28 Copyright Bruce Merry bmerry ' ' gmail dot.