This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 473: Fundamental Algorithms, Spring 2012 Homework 3 (due Tuesday, 23:55:00, February 14, 2012) Collaboration Policy & submission guidelines: See homework 1. Each student individually have to also do quiz 3 online. Version: 1.0 1. ( 30 pts. ) Saving the world, one pancake at a time. Suppose we have a stack of n pancakes of different sizes. We want to sort the pancakes so that the smaller pancakes are on top of the larger pancakes. The only operation we can perform is a flip- insert a spatula under the top k pancakes, for some k between 1 and n , and flip them all over. (A) ( 15 pts. ) Describe an algorithm to sort an arbitrary stack of n pancakes and give a bound on the number of flips that the algorithm makes. Assume that the pancake information is given to you in the form of an n element array A . A [ i ] is a number between 1 and n and A [ i ] = j means that the j ’th smallest pancake is in position i from the bottom; in other words A  is the size of the bottom most pancake (relative to the...
View Full Document
- Spring '08
- Algorithms, American films, Big O notation, Analysis of algorithms, Computational complexity theory, pancakes