1.

What is the time complexity for a given pancake sort given it undergoes “n” flip operations?(a) O(n)(b) O(n^2)(c) O(n^3)(d) O(2n)This question was addressed to me during an online exam.My question is taken from Pancake Sort in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) O(n^2)

Explanation: Most SORTING algorithms try to SORT making the least number of comparisons but in pancake sort we try to sort USING as few REVERSALS as possible. Because the total number of flip operations PERFORMED in a pancake sort is O(n), the overall time complexity is O(n^2).



Discussion

No Comment Found

Related InterviewSolutions