Data Structure Multiple Choice Questions on “Pancake Sort”.
1. What is the time complexity for a given pancake sort given it undergoes “n” flip operations? Answer: b 2. Which operation is most essential to the process of pancake sort? Answer: a 3. There is one small error in the following flip routine. Find out which line it is on. a) Line 3 Answer: c 4. How many flips does the simplest of pancake sorting techniques require? 5. Pancake Sorting appears in which of the following? Answer: c 6. In addition to the pancake sorting problem, there is the case of the burnt pancake problem in which we are dealing with pancakes (discs) that are burnt on one side only. In this case it is taken that the burnt side must always end up _______ 7. In a computational complexity theory, a problem with decision making is said to be NP-complete when it is both in NP and NP-hard. What does NP mean? 8. When we realize a specific implementation of a pancake algorithm, every move when we find the greatest of the sized array and flipping can be modeled through __________ Answer: d 9. The Pancake Problems (1975, 1979, 1973) did NOT involve which of the following people? Answer: d 10. There is a one line error in the following routine. Find that line. a) Line 2 Answer: b & Algorithms.
a) O(n)
b) O(n2)
c) O(n3)
d) O(2n)
Clarification: 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).
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
Clarification: 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. 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 }
b) Line 5
c) Line 7
d) Line 9
Clarification: 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.
a) 3n−3 flips
b) 2n-4 flips
c) 2n-3 flips
d) 3n-2 flips
Answer: c
Clarification: The minimum number of flips required to sort any stack of n pancakes has been shown to lie between 1.087n and 1.636n. using average of that 1.36n and extracting that for values of n>1. We have 1.36, 2.72, 4.08 etc. This matches best with 2n-3 which is equal to 1, 3, 5, 7, 9, etc. An upper bound of 2n-3 comes by iteratively using the next largest element in its correct place using two flips.
a) Frequency Scaling
b) Storage Virtualization
c) Parallel Processing
d) Neural Networking
View Answer
Clarification: Pancake Sorting finds application in educational use not to mention parallel processing networks by providing optimal routing algorithms between networks.
a) Faced down
b) Faced up
c) It doesn’t matter
d) Both sides are burnt
Answer: a
Clarification: A varation of this pancake is with burnt pancakes. Here each pancake has a burnt side and all pancakes must, in addition, end up with the burnt side on bottom. It is a more difficult version of the regular pancake problem.
a) Non Polynomial time
b) Non-deterministic Probabilistic
c) Non-deterministic Polynomial time
d) Non Probabilistic time
Answer: c
Clarification: Although any given solution to an NP-complete problem can be validated quickly in polynomial time; there is no way to efficiently locate a solution to begin with. The unique characteristic of NP-complete problems is that no fast solution to them is known and hence NP-complete problems are said to be non-deterministic polynomial time.
a) Combinations
b) Exponential functions
c) Logarithmic functions
d) Permutations
Clarification: Here when we flipping the array or stack, we have to take utmost priority to preserve the order of the list so that that sorting doesnt become invalid. Hence we use permutations, we are ensuring that order matters.
a) Bill Gates
b) Jacob Goodman
c) Christos Papadimitriou
d) John Goodman
Clarification: (Jacob Goodman – 1975) What is the maximum number of flips needed to sort a permutation of [n] into ascending order?
(Bill Gates and Christos Papadimitriou – 1979) What is the maximum number of flips needed to sort a signed permutation of [n] into ascending order with all positive signs? 1. int Max(int a[], int n)
2. {
3. int mi, i;
4. for (mi = 0, i = 0; i < n; i++)
5. if (a[i] > a[mi])
6. mi = i;
7. return mi;
8. }
b) Line 4
c) Line 6
d) Line 5
Clarification: The increment condition in the for loop declaration is incorrect. We should use ++i instead of i++.
