1.

Which is the worst method of choosing a pivot element?(a) first element as pivot(b) last element as pivot(c) median-of-three partitioning(d) random element as pivotI got this question by my school principal while I was bunking the class.My doubt stems from Quicksort in chapter Sorting of Data Structures & Algorithms II

Answer»

Right ANSWER is (a) FIRST ELEMENT as PIVOT

The best I can explain: CHOOSING the first element as pivot is the worst method because if the input is pre-sorted or in reverse order, then the pivot provides a poor partition.



Discussion

No Comment Found

Related InterviewSolutions