Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS 15-251 Fall 2O05 Lecture 1 Aug 29 th, 2OO5 Aug 29 th, 2OO5 Carnegie.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science for Some.
Advertisements

MATH 224 – Discrete Mathematics
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Great Theoretical Ideas in Computer Science
Lower bound: Decision tree and adversary argument
Recursion Lecture 18: Nov 18.
Lecture 12: Lower bounds By "lower bounds" here we mean a lower bound on the complexity of a problem, not an algorithm. Basically we need to prove that.
Introduction to Algorithms
CSC 2300 Data Structures & Algorithms March 16, 2007 Chapter 7. Sorting.
CLOSE Please YOUR LAPTOPS, and get out your note-taking materials.
Cooking for Computer Scientists. I understand that making pancakes can be a dangerous activity and that, by doing so, I am taking a risk that I.
Lectures on Network Flows
Bioinformatics Chromosome rearrangements Chromosome and genome comparison versus gene comparison Permutations and breakpoint graphs Transforming Men into.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Introduction to Bioinformatics Algorithms Greedy Algorithms And Genome Rearrangements.
Discrete Structures & Algorithms EECE 320 : UBC : Spring 2009 Matei Ripeanu 1.
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
Genome Rearrangements CSCI : Computational Genomics Debra Goldberg
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2004 Lecture 1 Jan 13, 2004 Carnegie Mellon University.
Pancakes With A Problem Steven Rudich The chef at our place is sloppy, and when he prepares a stack of pancakes they come out all different sizes.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Vince Conitzer COMPSCI 102 Fall 2007 Lecture 1 August 27, 2007 Duke University.
Cooking for Computer Scientists. I understand that making pancakes can be a dangerous activity and that, by doing so, I am taking a risk that I.
Advanced Counting Techniques
CompSci 102 Spring 2012 Prof. Rodger January 11, 2012.
CS 103 Discrete Structures Lecture 01 Introduction to the Course
Analysis CS 367 – Introduction to Data Structures.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS Fall 2006 Lecture 1 Aug 29 th, 2OO6 Aug 29 th, 2OO6 Carnegie.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Great Theoretical Ideas in Computer Science.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 1 Prof. Charles E. Leiserson.
Genome Rearrangements Unoriented Blocks. Quick Review Looking at evolutionary change through reversals Find the shortest possible series of reversals.
Greedy Algorithms And Genome Rearrangements An Introduction to Bioinformatics Algorithms (Jones and Pevzner)
1 Chapter 7: Sorting (Insertion Sort, Shellsort) CE 221 Data Structures and Algorithms Izmir University of Economics Text: Read Weiss, § 7.1 – 7.4.
Genome Rearrangements [1] Ch Types of Rearrangements Reversal Translocation
Greedy Algorithms And Genome Rearrangements
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Integrals  In Chapter 2, we used the tangent and velocity problems to introduce the derivative—the central idea in differential calculus.  In much the.
Andrew’s Leap 2011 Pancakes With A Problem Steven Rudich.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2005 Lecture 3 Jan 18, 2005 Carnegie Mellon University.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
Introduction to Bioinformatics Algorithms Chapter 5 Greedy Algorithms and Genome Rearrangements By: Hasnaa Imad.
Chapter 9 sorting. Insertion Sort I The list is assumed to be broken into a sorted portion and an unsorted portion The list is assumed to be broken into.
Great Theoretical Ideas in Computer Science for Some.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
1 Chapter 7: Sorting (Insertion Sort, Shellsort) CE 221 Data Structures and Algorithms Izmir University of Economics Text: Read Weiss, § 7.1 – 7.4.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going.
CMPT 438 Algorithms.
Pancakes With A Problem!
Lectures on Network Flows
Pancakes With A Problem!
Basic Counting.
Chapter 11 Limitations of Algorithm Power
Cooking for Computer Scientists.
Counting II: Recurring Problems And Correspondences
Mathematical Analysis of Algorithms
Counting II: Recurring Problems And Correspondences
Induction: One Step At A Time
Counting I: Choice Trees and Correspondences
Bounds for Sorting by Prefix Reversal -- Pancake Problem
Presentation transcript:

Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS Fall 2O05 Lecture 1 Aug 29 th, 2OO5 Aug 29 th, 2OO5 Carnegie Mellon University

Course Staff Profs:Anupam Gupta John Lafferty John Lafferty TAs:Kanat Tangwongsan Yinmeng Zhang Please check the webpages regularly!

Please feel free to ask questions! ((( )))

Course Document You must read this carefully. 1.Grading formula for the course. a)40% homework b) 5% in-class quizzes c)25% in-recitation tests d)30% final 2.Seven points a day late penalty. 3.Collaboration/Cheating Policy a)You may NOT share written work. b)We reuse homework problems.

Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS Fall 2O05 Lecture 1 Aug 29 th, 2OO5 Aug 29 th, 2OO5 Carnegie Mellon University

The chef at our place is sloppy, and when he prepares a stack of pancakes they come out all different sizes. Therefore, when I deliver them to a customer, on the way to the table I rearrange them (so that the smallest winds up on top, and so on, down to the largest at the bottom) I do this by grabbing several from the top and flipping them over, repeating this (varying the number I flip) as many times as necessary.

Developing A Notation: Turning pancakes into numbers

How do we sort this stack? How many flips do we need?

4 Flips Are Sufficient

Algebraic Representation X = The smallest number of flips required to sort: ?  X  ? Upper Bound Lower Bound

Algebraic Representation X = The smallest number of flips required to sort: ?  X  4 Upper Bound Lower Bound

Better Upper/Lower Bound? ?  X  4

4 Flips are necessary in this case Flip 1 has to put 5 on bottom Flip 2 must bring 4 to top.

Upper Bound Lower Bound 4  X  4 X = 4

5 th Pancake Number The number of flips required to sort the worst case stack of 5 pancakes. ?  P 5  ? Upper Bound Lower Bound P 5 =

5 th Pancake Number The number of flips required to sort the worst case stack of 5 pancakes. 4  P 5  ? Upper Bound Lower Bound P 5 =

..... The 5 th Pancake Number: The MAX of the X’s X1X1 X2X2 X3X3 X 119 X

The 5 th Pancake Number: The MAX of the X’s X1X1 X2X2 X3X3 X 119 X

X1X1 X2X2 X3X3 X 119 X P 5 = MAX over s 2 stacks of 5 of MIN # of flips to sort s

P n = MAX over s 2 stacks of n pancakes of MIN # of flips to sort s P n = The number of flips required to sort the worst-case stack of n pancakes.

P n = MAX over s 2 stacks of n pancakes of MIN # of flips to sort s P n = The number of flips required to sort a worst-case stack of n pancakes.

Be Cool. Learn Math-speak. P n = The number of flips required to sort a worst-case stack of n pancakes.

What is P n for small n? Can you do n = 0, 1, 2, 3 ?

Initial Values Of P n n0123 PnPn 0013

P 3 = requires 3 Flips, hence P 3 ≥ 3. ANY stack of 3 can be done by getting the big one to the bottom ( ≤ 2 flips), and then using ≤ 1 extra flip to handle the top two. Hence, P 3 = 3.

n th Pancake Number The number of flips required to sort a worst case stack of n pancakes. ?  P n  ? Upper Bound Lower Bound P n =

Bracketing: What are the best lower and upper bounds that I can prove? ≤ f(x) ≤ [ ]

?  P n  ? Take a few minutes to try and prove upper and lower bounds on P n, for n > 3.

Bring biggest to top. Place it on bottom. Bring next largest to top. Place second from bottom. And so on… Bring-to-top Method

Upper Bound On P n : Bring To Top Method For n Pancakes If n=1, no work required - we are done! Otherwise, flip pancake n to top and then flip it to position n. Now use: Bring To Top Method For n-1 Pancakes Total Cost: at most 2(n-1) = 2n –2 flips.

Better Upper Bound On P n : Bring To Top Method For n Pancakes If n=2, at most one flip and we are done. Otherwise, flip pancake n to top and then flip it to position n. Now use: Bring To Top Method For n-1 Pancakes Total Cost: at most 2(n-2) + 1 = 2n –3 flips.

Bring to top not always optimal for a particular stack Bring-to–top takes 5 flips, but we can do in 4 flips

?  P n  2n-3 What other bounds can you prove on P n ?

Better Upper/Lower Bounds?

9 16 Suppose a stack S contains a pair of adjacent pancakes that will not be adjacent in the sorted stack. Any sequence of flips that sorts stack S must involve one flip that inserts the spatula between that pair and breaks them apart. Breaking Apart Argument

9 16 Suppose a stack S contains a pair of adjacent pancakes that will not be adjacent in the sorted stack. Any sequence of flips that sorts stack S must involve one flip that inserts the spatula between that pair and breaks them apart. Furthermore, this same principle is true of the “pair” formed by the bottom pancake of S and the plate. Breaking Apart Argument

n  P n n n-1 S Suppose n is even. S contains n pairs that will need to be broken apart during any sequence that sorts stack S.

n  P n Suppose n is even. S contains n pairs that will need to be broken apart during any sequence that sorts stack S S Detail: This construction only works when n>2

n  P n Suppose n is odd. S contains n pairs that will need to be broken apart during any sequence that sorts stack S n n-1 S

n  P n S Detail: This construction only works when n>3 Suppose n is odd. S contains n pairs that will need to be broken apart during any sequence that sorts stack S.

n  P n  2n – 3 for n ≥ 3 Bring To Top is within a factor of two of optimal!

Starting from ANY stack we can get to the sorted stack using no more than P n flips. n  P n  2n – 3 for n ≥ 3

From ANY stack to sorted stack in ≤ P n. Reverse the sequences we use to sort. From sorted stack to ANY stack in ≤ P n ? ((( )))

Hence, From ANY stack to ANY stack in ≤ 2P n. From ANY stack to sorted stack in ≤ P n. From sorted stack to ANY stack in ≤ P n ?

From ANY stack to ANY stack in ≤ 2P n. Can you find a faster way than 2P n flips to go from ANY to ANY? ((( )))

Any-to-Any? S: 4,3,5,1,2 T: 5,2,4,3,1

From ANY Stack S to ANY stack T in ≤ P n Rename the pancakes in S to be 1,2,3,..,n. Rewrite T using the new naming scheme that you used for S. T will be some list:  (1),  (2),..,  (n). The sequence of flips that brings the sorted stack to  (1),  (2),..,  (n) will bring S to T. S: 4,3,5,1,2 T: 5,2,4,3,1 1,2,3,4,53,5,1,2,4

The Known Pancake Numbers n PnPn

P 14 Is Unknown 14! Orderings of 14 pancakes. 14! = 87,178,291,200

Is This Really Computer Science?

Posed in Amer. Math. Monthly 82 (1) (1975), “Harry Dweighter” a.k.a. Jacob Goodman

(17/16)n  P n  (5n+5)/3 William Gates & Christos Papadimitriou Bounds For Sorting By Prefix Reversal. Discrete Mathematics, vol 27, pp 47-57, 1979.

(15/14)n  P n  (5n+5)/3 H. Heydari & H. I. Sudborough On the Diameter of the Pancake Network. Journal of Algorithms, vol 25, pp 67-94, 1997.

Permutation Any particular ordering of all n elements of an n element set S, is called a permutation on the set S. Example: S = {1, 2, 3, 4, 5} One possible permutation: *4*3*2*1 = 120 possible permutations on S

Permutation Any particular ordering of all n elements of an n element set S, is called a permutation on the set S. Each different stack of n pancakes is one of the permutations on [1..n].

Representing A Permutation We have many ways to specify a permutation on S. Here are two methods: 1)We list a sequence of all the elements of [1..n], each one written exactly once. Ex: )We give a function  on S such that  (1)  (2)  (3)..  (n) is a sequence that lists [1..n], each one exactly once. Ex:  (1)=6  (2)=4  (3) = 5  (4) = 2  (4) = 1  (6) =3

A Permutation is a NOUN An ordering S of a stack of pancakes is a permutation.

A Permutation is a NOUN. A permutation can also be a VERB. An ordering S of a stack of pancakes is a permutation. We can permute S to obtain a new stack S’. Permute also means to rearrange so as to obtain a permutation of the original.

Permute A Permutation. I start with a permutation S of pancakes. I continue to use a flip operation to permute my current permutation, so as to obtain the sorted permutation.

There are n! = 1*2*3*4*…*n permutations on n elements. Easy proof in the first counting lecture.

Pancake Network: Definition For n! Nodes For each node, assign it the name of one of the n! stacks of n pancakes. Put a wire between two nodes if they are one flip apart.

Network For n=

Network For n=4

Pancake Network: Message Routing Delay What is the maximum distance between two nodes in the network? PnPn

Pancake Network: Reliability If up to n-2 nodes get hit by lightning the network remains connected, even though each node is connected to only n-1 other nodes. The Pancake Network is optimally reliable for its number of edges and nodes.

Mutation Distance

High Level Point Computer Science is not merely about computers and programming, it is about mathematically modeling our world, and about finding better and better ways to solve problems. This lecture is a microcosm of this exercise.

One “Simple” Problem A host of problems and applications at the frontiers of science

Study Bee Please read the course document carefully. You must hand in a signed cheating policy page.

Study Bee Definitions of: nth pancake number lower bound upper bound permutation Proof of: ANY to ANY in ≤ P n Important Technique: Bracketing

References Bill Gates & Christos Papadimitriou: Bounds For Sorting By Prefix Reversal. Discrete Mathematics, vol 27, pp 47-57, H. Heydari & H. I. Sudborough: On the Diameter of he Pancake Network. Journal of Algorithms, vol 25, pp 67-94, 1997