Quick sort - choosing first/starting element as pivot

Quick sort - choosing first/starting element as pivot


Quick Sort:


  1. Has the Time Complexity of O(n^2) in worst case
  2. Preferred Sorting technique in real-time applications
  3. Better than Bubble sort, Selection sort, Insertion sort
  4. Can be modified to achieve O(nlogn) complexity by modifying the code of choosing pivot element
  5. 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