2 Pancake sorting Suppose you are given a stack of n pancakes of different sizes. You...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2 Pancake sorting Suppose you are given a stack of n pancakes of different sizes. You must sort the pancakes so that smaller pancakes are on top of larger pancakes. The only operation you can perform is a flip: insert a spatula under the top k pancakes, for some integer k between 1 and n, and flip them all over. 2.1 Describe an algorithm to sort an arbitrary stack of n pancakes using O(n) flips. Exactly how many flips does your algorithm perform in the worst case? 2.2 For every positive integer n, describe a stack of n pancakes where your algorithm from 2.1 requires N(n) flips to sort. 2 Pancake sorting Suppose you are given a stack of n pancakes of different sizes. You must sort the pancakes so that smaller pancakes are on top of larger pancakes. The only operation you can perform is a flip: insert a spatula under the top k pancakes, for some integer k between 1 and n, and flip them all over. 2.1 Describe an algorithm to sort an arbitrary stack of n pancakes using O(n) flips. Exactly how many flips does your algorithm perform in the worst case? 2.2 For every positive integer n, describe a stack of n pancakes where your algorithm from 2.1 requires N(n) flips to sort.
Expert Answer:
Answer rating: 100% (QA)
21 P ancakeSort The goal is to sort the sequence in as few reversals as possible unlike a traditiona... View the full answer
Related Book For
Database management systems
ISBN: 978-0072465631
3rd edition
Authors: Raghu Ramakrishan, Johannes Gehrke, Scott Selikoff
Posted Date:
Students also viewed these algorithms questions
-
Suppose you are given a relation R with four attributes ABCD. For each of the following sets of FDs, assuming those are the only dependencies that hold for R, do the following: (a) Identify the...
-
Suppose you are given six resistors with respective resistances 1, 2, 3, 4, 5 and 6. How should you connect them in a tetrahedral network (one resistor per wire) so that a light bulb on the wire...
-
Suppose you are given these hypotheses: H0: 25, H1: > 25; and that the standard deviation from a sample of 100 is 2.4. What is the power of the test at a 5% level of significance if the...
-
Cinderella's income increases by 25%. She decides to increase her purchases of glass slippers by 40%. To her, glass slippers are a(n)____________good and her income elasticity of demand for glass...
-
(a) Cite the major differences between activation and concentration polarizations. (b) Under what conditions is activation polarization rate controlling?
-
Air at 1 atm and 208C flows in a 4-cm-diameter tube. The maximum velocity of air to keep the flow laminar is (a) 0.872 m/s (b) 1.52 m/s (c) 2.14 m/s (d) 3.11 m/s (e) 3.79 m/s
-
Darwin Ltd wants to focus on people, profits, planet. The board of directors has proposed linking top managers pay to broad measures of environmental sustainability, and worker and customer...
-
Wise Company completes these transactions during April of the current year (the terms of all its credit sales are 2/10, n/30). Apr. 2 Purchased $13,300 of merchandise on credit from Negi Company,...
-
31 The number of protons, electrons and neutrons in aluminium ion Al+ is Protons A. 27 B. 13 C. ABCD 32 32. D. 13 10 Electron 27 neutrons 14 14 14 10 14 17 14 The formula of the compound formed...
-
Suppose that you hate typing and hate filing. a. Draw a graph with "hours of typing" on the horizontal axis and "hours of filing" on the vertical. Do your indifference curves slope upward or...
-
Cardiovascular fitness has been dubbed the most critical aspect of physical fitness. Exercising our cardiovascular system helps ward off cardiovascular disease (heart attack, stroke, high blood...
-
What operational factors must an airline consider in selecting new aircraft?
-
Suppose you receive $100 at the end of each year for the next three years. a. If the interest rate is 7%, what is the present value of these cash flows? b. What is the future value in three years of...
-
Explain the rationale for the diferent branches of psychology using diferent techniques when applying the scientifc method.
-
Explain an unstructured selection interview.
-
Identify the disciplines that contribute to organizational behaviour and assess the signifcance of psychology as a contributory discipline.
-
Write a Scheme program for each of the following. You can use the "linprog" server for your implementation - it has Scheme installed in it. a) To reverse a list. You are not allowed to use the...
-
Explain how the graph of each function can be obtained from the graph of y = 1/x or y = 1/x 2 . Then graph f and give the (a) Domain (b) Range. Determine the largest open intervals of the domain over...
-
What are the responsibilities of a DBA? If we assume that the DBA is never interested in running his or her own queries, does the DBA still need to understand query optimization? Why?
-
Suppose that duplicates are handled using the approach without overflow pages discussed in Section 10.7. Describe an algorithm to search for the left-most occurrence of a data entry with search key...
-
Give an algorithm for testing whether a relation scheme is in BCNF. The algorithm should be polynomial in the size of the set of given FDs. (The size is the sum over all FDs of the number of...
-
The position of a particle undergoing simple harmonic motion is given by \(x(t)=20 \cos (8 \pi t)\), where \(x\) is in millimeters and \(t\) is in seconds. For this motion, what are the (a)...
-
Fill in the blanks to make the following statements correct. a. It is difficult to compare two or more data series when absolute numbers and different units are used. For that reason we construct...
-
Fill in the blanks to make the following statements correct. a. The term quantity demanded refers to ___________ purchases by consumers, whereas quantity exchanged refers to ___________ purchases by...
Study smarter with the SolutionInn App