- This algorithm uses idea of divide and conquer.
- Find the element called pivot which divides the array into two halves
- Left side elements should be smaller than the pivot
- Right side elements are geater than the pivot
- Steps
- Bring the pivot to its appropriate position such that left of the pivot is smaller and right is greater.
- Quick sort left part
- Quick sort right part
- There are many different versions of quickSort that pick pivot in different ways.
- Always pick first element as pivot.
- Always pick last element as pivot (implemented below)
- Pick a random element as pivot.
- Pick median as pivot
- Reference:
Wednesday, 24 October 2018
Quick Sort in java
About Unknown
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment