Quicksort Algorithm

Demonstrate the quicksort algorithm to sort a list of data elements

Questions by Dheerendra_juli

Showing Answers 1 - 3 of 3 Answers

adnan15110

  • Jan 3rd, 2010
 

  1. Pick an element, called a pivot from the list.
  2. Reorder the list so that all elements which are less than the pivot come before the pivot and so that all elements greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
  3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements. (reference: wikipedia)
      For example: 9 - 7 - 10 - 3- 8 -12- 5- 16 (unsorted list)
                           9(pivot) - 7 - 10 - 3- 8 -12- 5- 16 (pick a pivot   here  took  9)
                           7 - 3 - 8 -  5 (parition 1)- 9 - (partion 2) 12 - 10 - 16
                           7(pivot) - 3 - 8 -  5 (parition 1)- 9 - (partion 2) 12(pivot) - 10 - 16
                           3 - 5 - 7 - 8(parition 1) - 9 - (partion 2) 10 - 12- 16

In this way recursively sorts each partition by took a pivot.the performance on quick sort depends largely on the choice of pivot.

Worse case complexity (n^2)
Average case complexity (n logn)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions