# Data Structure Questions and Answers-Pancake Sort

## Data Structure Questions and Answers-Pancake Sort

 Question 1
What is the time complexity for a given pancake sort given it undergoes "n" flip operations?
 A O(n) B O(n2) C O(n3) D O(2n)
Question 1 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(n2).

 Question 2
Which operation is most essential to the process of pancake sort?
 A Flip the given data B Find the largest of given data C Finding the least of given data D Inserting something into the given data
Question 2 Explanation:
When we use pancake sort, we sort the array to find the largest, and then flip the array at that point to bring that value to the bottom of the pancake stack. The size of the array that we are dealing with is then reduced and the process continues. Flip operation is the most important function in the pancake sort technique.

 Question 3
There is one small error in the following flip routine. Find out which line it is on.

	1	void flip(int arr[], int i) 	2	{ 	3	 int t, init = 0; 	4	 while (init < i) 	5	 { 	6		 t = arr[init]; 	7		 arr[i] = arr[init] ; 	8		 arr[i] = t; 	9		 init++; 	10		 i--; 	11	 } 	12	}
 A Line 3 B Line 5 C Line 7 D Line 9
Question 3 Explanation:
After initialization of the array titled arr; for each while loop iteration of increasing init, we should make arr[init]=arr[i]. This makes sure that the changes will be made in order to flip the order of the array that was to be flipped. Here in line 7 it has been written in reverse and is incorrect.

 Question 4
How many flips does the simplest of pancake sorting techniques require?
 A 3n-3 flips B 2n-4 flips C 2n-3 flips D 3n-2 flips