Quick sort - choosing first/starting element as pivot
Quick Sort:
Quick Sort:
- Has the Time Complexity of O(n^2) in worst case
- Preferred Sorting technique in real-time applications
- Better than Bubble sort, Selection sort, Insertion sort
- Can be modified to achieve O(nlogn) complexity by modifying the code of choosing pivot element
- Logic:
- Choose a pivot element
- Partition the array into subarrays such that the sub-array having elements less than falls in the left side of the pivot element
- and the sub-array with elements greater than the pivot element falls in the right side of the pivot element
- merge the sub-arrays
- recursively do the above steps until there is a single element in the sub-array