Question

In: Computer Science

Question 3. Find a solution to the instance π = 2 3 1 4 5 7...

Question 3. Find a solution to the instance π = 2 3 1 4 5 7 6 of the Pancake Flipping problem using a greedy approach (15 points). Describe your algorithm using pseudocode. (10 points)

Solutions

Expert Solution

the pancake sorting pseudo code is in the second image and the given problem is solved using the same in the first image.

in pancake sorting we find the max element in a given array and bring it to top using 3 flips.

this process is then repeated for the remaining elements till the whole array is sorted.

this is similar to how selection sort works except we use flips to bring a element to top instead of directly exchanging positions.


Related Solutions

4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1,...
4) Let ? = {2, 3, 5, 7}, ? = {3, 5, 7}, ? = {1, 7}. Answer the following questions, giving reasons for your answers. a) Is ? ⊆ ?? b)Is ? ⊆ ?? c) Is ? ⊂ ?? d) Is ? ⊆ ?? e) Is ? ⊆ ?? 5) Let ? = {1, 3, 4} and ? = {2, 3, 6}. Use set-roster notation to write each of the following sets, and indicate the number of elements in...
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5....
Maria says that 4 2/3 x 7 1/5 = 4 x 7 + 2/3 x 1/5. Explain why Maria has made a good attempt, but her answer is not correct. Explain how to work with what Maria has already written and modify it to get the correct answer. In other words, don’t just start from scratch and show Maria how to do the problem, but rather take what she has already written, use it, and make it mathematically correct. Which...
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5...
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5 8 7 6 5 7 7 6 7 8 8 8 9 7 8 10 12 11 Test the significance of the correlation coefficient. Then use math test scores (X) to predict physics test scores (Y).  Do the following: Create a scatterplot of X and Y. Write the regression equation and interpret the regression coefficients (i.e., intercept and slope). Predict the physics score for each....
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4 6 5 4 5 3 7 5 5 4 2 6 5 6 6] This is my dataset Find mean, median, mode, variance, standard deviation, coefficient of variation, range, 70th percentile, 3rdquartile of the data and skewness and define what each of these statistics measure. For example, mean is a measure of the central tendency, what about the rest? Use Chebyshev’s rule to find...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4 6 5 4 5 3 7 5 5 4 2 6 5 6 6] This is my dataset Split the dataset in two equal parts. You have 30 datavalues. If you split the data in two equal parts each part will contain 15 data values.  Call the first part Y and second part X.Draw scatter plot of the 2 datasets, X being on the horizontal...
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 ....
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 . C) From the point (1,2,3) to the line ?=〈−?,4−?,1+4?〉 .
Find regression line for the data X 0   1   2   3    4   5   6   7  8          &nbsp
Find regression line for the data X 0   1   2   3    4   5   6   7  8               [3 MARKS] Y 11 21 31 41 51 61 71 81 91 b. X  0   2   4   6   8  10                            [3 MARKS]       Y  12 15 17 18 20 22
Find the roots of the following equation in [−π, π] 2x 2 − 4 cos(5x) −...
Find the roots of the following equation in [−π, π] 2x 2 − 4 cos(5x) − 4x sin x + 1 = 0 by using the Newton’s method with accuracy 10^(−5) . how do I solve this using a computer
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7...
Step 2 Data Set A x 1 2 3 4 5 6 7 y 7 7 7 9 9 9 10 Data Set B x 1 2 3 4 5 6 7 8 9 10 11 y 4 6 6 6 8 9 9 9 10 10 10 Step 2 Find the equation for the least-squares line, and graph the line on the scatter plot. Find the sample correlation coefficient r and the coefficient of determination r2. Is r significant?...
Given an array with data 3, 6, 4, 1, 5, 2, 6, 5, 3, 7, 4 using random select to find the 9 th smallest number
Given an array with data 3, 6, 4, 1, 5, 2, 6, 5, 3, 7, 4 using random select to find the 9 th smallest number (use the last element in each sequence as pivot). Show the intermediate steps (the result of each recursive step including the pivot, k’s value and grouping).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT