Be the first user to complete this post

  • 0
Add to List
Medium

Quick Sort Implementation

Objective: Write an algorithm to sort an array in increasing or decreasing order using Quick Sort.

Input:  An Array arrA[]

Output: A sorted array.

Approach:

  • Choose any element from the array and call it as pivot element, Example here we have selected middle element as pivot
  • Place all the elements smaller than pivot in the left side of pivot.
  • Place all the elements greater than pivot in the right side of pivot.
  • Sort left side and right side recursively.

Example:

Quick Sort Example
Quick Sort Example

Code:


Output:

UnSorted : 2 1 8 4 0 9 3 11
Quick Sorted : 0 1 2 3 4 8 9 11



Also Read: