Pancakes With A Problem!

Slides:



Advertisements
Similar presentations
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Advertisements

Great Theoretical Ideas in Computer Science
Lower bound: Decision tree and adversary argument
CompSci 102 Discrete Math for Computer Science April 19, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
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.
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.
Introduction to Bioinformatics Algorithms Greedy Algorithms And Genome Rearrangements.
Discrete Structures & Algorithms EECE 320 : UBC : Spring 2009 Matei Ripeanu 1.
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.
CompSci 102 Discrete Math for Computer Science March 22, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
MATH 224 – Discrete Mathematics
Lecture 9. Arithmetic and geometric series and mathematical induction
CompSci 102 Spring 2012 Prof. Rodger January 11, 2012.
Discrete Mathematics, 1st Edition Kevin Ferland
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.
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.
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.
Greedy Algorithms And Genome Rearrangements An Introduction to Bioinformatics Algorithms (Jones and Pevzner)
Genome Rearrangements [1] Ch Types of Rearrangements Reversal Translocation
Greedy Algorithms And Genome Rearrangements
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.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
CompSci 102 Discrete Math for Computer Science March 20, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
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.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
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.
Section 3.2: Sequences and Summations. Def: A sequence is a function from a subset of the set of integers (usually the set of natural numbers) to a set.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
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.
Sporadic and Related groups Lecture 15 Introduction to Fusion.
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
CS1022 Computer Programming & Principles
Chapter 1 Logic and Proof.
Chapter 7: Sorting (Insertion Sort, Shellsort)
Greedy Algorithms.
Lecture 3: Parallel Algorithm Design
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
Lectures on Network Flows
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
CSE 5290: Algorithms for Bioinformatics Fall 2009
Algorithm design and Analysis
Complexity Present sorting methods. Binary search. Other measures.
Pancakes With A Problem!
Bitonic Sorting and Its Circuit Design
3.5 Minimum Cuts in Undirected Graphs
Bacteria Objectives To identify & obtain necessary information to solve problems. To solve substantial problems by breaking them down into smaller parts.
Basic Counting.
3.4 Push-Relabel(Preflow-Push) Maximum Flow Alg.
Advanced Analysis of Algorithms
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Counting Discrete Mathematics.
Basic Counting Lecture 9: Nov 5, 6.
Cooking for Computer Scientists.
Discrete Mathematics for Computer Science
Mathematical Analysis of Algorithms
Counting II: Recurring Problems And Correspondences
Bounds for Sorting by Prefix Reversal -- Pancake Problem
Algorithms Tutorial 27th Sept, 2019.
Presentation transcript:

Pancakes With A Problem! Discrete Mathematics for Computer Science Bruce Maggs COMPSCI 230 Lecture 1 Duke University Pancakes With A Problem!

Course Staff Prof: Bruce Maggs (bmm@cs.duke.edu) TA: Mahanth Gowda (mahanth.gowda@duke.edu) http://www.cs.duke.edu/courses/fall12/compsci230 Lectures developed at Carnegie Mellon, primarily by Prof. Steven Rudich.

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

Course Document You must read this carefully. Grading formula for the course. 40% homework 30% quizzes 30% final Seven points a day late penalty. Collaboration/Cheating Policy You may NOT share written work. We reuse homework problems.

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

Developing A Notation: Turning pancakes into numbers 1 2 3 4 5

Developing A Notation: Turning pancakes into numbers 5 2 3 4 1

Developing A Notation: Turning pancakes into numbers 52341

How do we sort this stack? How many flips do we need? 5 2 3 4 1

4 Flips Are Sufficient 52341 14325 23415 43215 12345

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

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

4 Flips Are Necessary If we could do it in 3 flips 52341 14325 41325 If we could do it in 3 flips Flip 1 has to put 5 on bottom Flip 2 must bring 4 to top (if it didn’t we’d need more than 3 flips). If we don’t put 5 on the bottom with Flip 1, then it goes somewhere in the middle. In order to finish in three flips, we have to immediately put it back on top (undoing the first flip!), then put it on the bottom, but then we don’t have sorted order.

?  X  4 Lower Bound

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

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

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

The 5th Pancake Number: The MAX of the X’s 1 2 3 52341 119 120 . . . . . . . X1 X2 X3 4 X119 X120

P5 = MAX over s  stacks of 5 of MIN # of flips to sort s 1 2 3 52341 199 120 . . . . . . . X1 X2 X3 4 X119 X120

MAX over s  stacks of n pancakes of MIN # of flips to sort s Or, Pn MAX over s  stacks of n pancakes of MIN # of flips to sort s Or, The number of flips required to sort a worst-case stack of n pancakes.

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

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

Initial Values Of Pn n 1 2 3 Pn

P3 = 3 1 3 2 requires 3 Flips, hence P3 ≥ 3. ANY stack of 3 can be done in 3 flips. Get the big one to the bottom (· 2 flips). Use · 1 more flip to handle the top two. Hence, P3 ≤ 3.

nth Pancake Number ?  Pn  ? Pn = Number of flips required to sort a worst case stack of n pancakes. Upper Bound ?  Pn  ? Lower Bound

Take a few minutes to try and prove bounds on Pn, for n>3.

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

Upper Bound On Pn: Bring To Top Method For n Pancakes If n=1, no work - we are done. Else: 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 Pn: Bring To Top Method For n Pancakes If n=2, use one flip and we are done. Else: 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 52341 14325 41325 23145 32145 Should be an example of stack that uses more than 5 flips with bring to top. It should show that P5=5 cant be concluded with bring to top. 5 flips, but can be done in 4 flips

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

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.

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.

n  Pn S 2 4 6 8 . . n 1 3 5 7 . . n-1 Suppose n is even. Such a stack S contains n pairs that must be broken apart during any sequence that sorts stack S.

Detail: This construction only works when n>2 n  Pn S 21 Suppose n is even. Such a stack S contains n pairs that must be broken apart during any sequence that sorts stack S. Detail: This construction only works when n>2

n  Pn S 1 3 5 7 . . n 2 4 6 8 . . n-1 Suppose n is odd. Such a stack S contains n pairs that must be broken apart during any sequence that sorts stack S.

Detail: This construction only works when n>3 n  Pn S 132 Suppose n is odd. Such a stack S contains n pairs that must be broken apart during any sequence that sorts stack S. Detail: This construction only works when n>3

Bring To Top is within a factor of two of optimal! n ≤ Pn ≤ 2n – 3 (for n ≥ 3) Bring To Top is within a factor of two of optimal!

n ≤ Pn ≤ 2n – 3 (for n ≥ 3) So starting from ANY stack we can get to the sorted stack using no more than Pn flips.

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

From ANY stack to sorted stack in ≤ Pn. From sorted stack to ANY stack in ≤ Pn. Hence, From ANY stack to ANY stack in ≤ 2Pn.

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

From ANY Stack S to ANY stack T in ≤ Pn Rename the pancakes in T to be 1,2,3,..,n. T : 5, 2, 4, 3, 1 Tnew : 1, 2, 3, 4, 5 π(5), π(2), … …, π(1) Rewrite S using p(1),p(2),..,p(n) S : 4, 3, 5, 1, 2 Snew : π(4), π(3), … …, π(2) 3, 4, 1, 5, 2

From ANY Stack S to ANY stack T in ≤ Pn Tnew : 1, 2, 3, 4, 5 S : 4, 3, 5, 1, 2 Snew : 3, 4, 1, 5, 2 The sequence of steps that brings Snew to Tnew (sorted stack) also brings S to T

The Known Pancake Numbers Pn 1 2 3 4 5 6 7 8 9 10 11 12 13 0 1 3 4 5 7 8 9 10 11 13 14 15

P14 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  Pn  (5n+5)/3 Bill Gates & Christos Papadimitriou: Bounds For Sorting By Prefix Reversal. Discrete Mathematics, vol 27, pp 47-57, 1979.

(15/14)n  Pn  (5n+5)/3 H. Heydari & Ivan H. 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} Example permutation: 5 3 2 4 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 choices of how to specify a permutation on S. Here are two methods: List a sequence of all elements of [1..n], each one written exactly once. Ex: 6 4 5 2 1 3 Give a function  on S s.t. (i) denotes the permuted position of element i, for i[1..n], mapping exactly one element of S to each position Ex: (6)=1 (4)=2 (5)=3 (2)=4 (1)=5 (3)=6

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

A Permutation is a NOUN Permute is also 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.

I start with a permutation S of pancakes. 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.

Ultra-Useful Fact There are n! = n*(n-1)*(n-2) … 3*2*1 permutations on n elements. Proof: in the first counting lecture.

Pancake Network This network has n! nodes Assign each node the name of one of the possible n! stacks of pancakes. Put a wire between two nodes if they are one flip apart.

Network For n=3 213 123 312 321 132 231

Network For n=4

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

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

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

Study Bee Definitions of: nth pancake number lower bound upper bound permutation Proof of: ANY to ANY in ≤ Pn Study Bee

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