Heapsort
- Make an in-place Heap (Ordered Tree)
- Sort by moving root to end (as root is largest)
- Repeat steps 1&2 for element [0 to last-1] till value of last is1
QuickSort - 2-3 times faster than Heapsort
- Select a Pivot Point ( say last element )
- Keep swapping the elements and reach position i such that
- element [ 0 to i ] < element [i] < element [ i to last]
- The element at i is not at its sorted position.
- Repeat steps 1&2 for two halves around the pivot point.
- The algo performance depends on the selection of the pivot point.
Mergesort
- Divide the array till we get 1 element array.
- Merge the element arrays while maintaining the sort order.
- Highest space complexity O(n)
Insertsort
- Insert an element to its correct position in a partially sorted array.
- Sorting starts by finding the correct element for position 0,1,2.. so on till last
Bubblesort
- Smaller elements slowly bubble up the sorted list.
- After first loop the last element is the largest
No comments:
Post a Comment