Wednesday, 24 October 2018

Quick Sort in java


  • 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:

No comments:

Post a Comment

Search This Blog

Contact us

Name

Email *

Message *