Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists? – Searching and Sorting – Quick Sort in its general form is an in-place sort. whereas merge sort requires O(N) extra storage, N denoting the array size which may be quite expensive.
quicksort code
QuickSort on Doubly Linked List – Searching and sorting -. The idea is simple, we first find out pointer to last node. Once we have pointer to last node, we can recursively sort the linked list using pointers to first and last nodes of linked list.
QuickSort on Singly Linked List – Searching and sorting – Quick Sort on Doubly Linked List is discussed here.In Singly linked list was given as an exercise. Following is C++ implementation for same.
Iterative Quick Sort – Searching and Sorting – Partition process is same in both recursive and iterative. The same techniques to choose optimal pivot can also be applied to iterative version.
When does the worst case of Quicksort occur? – Searching and sorting – Since these cases are very common use cases, the problem was easily solved by choosing either a random index for the pivot.
Merge Sort – searching and sorting algorithm – Like QuickSort, Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves.