15-251 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.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

Max Cut Problem Daniel Natapov.
Great Theoretical Ideas in Computer Science
Today’s Daily Quiz will be given at the end of the hour. Please close your laptops and turn off and put away your cell phones, and get out your note-taking.
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.
CSC 2300 Data Structures & Algorithms March 16, 2007 Chapter 7. Sorting.
Lectures on Network Flows
Bioinformatics Chromosome rearrangements Chromosome and genome comparison versus gene comparison Permutations and breakpoint graphs Transforming Men into.
CS 197 Computers in Society Fall, Welcome, Freshmen!
COMP 110 Introduction to Programming Tabitha Peck M.S. January 9, 2008 MWF 3-3:50 pm Philips 367.
Introduction to Bioinformatics Algorithms Greedy Algorithms And Genome Rearrangements.
Discrete Structures & Algorithms EECE 320 : UBC : Spring 2009 Matei Ripeanu 1.
COMP171 Data Structures and Algorithm Huamin Qu Lecture 1 (Sept. 1, 2005)
COMP171 Data Structures and Algorithm Qiang Yang Lecture 1 ( Fall 2006)
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2004 Lecture 1 Jan 13, 2004 Carnegie Mellon University.
CSE115/ENGR160 Discrete Mathematics 01/17/12 Ming-Hsuan Yang UC Merced 1.
Modern Optics Lab Modern Optics Lab Introductory Meeting.
COMP 14 – 02: Introduction to Programming Andrew Leaver-Fay August 31, 2005 Monday/Wednesday 3-4:15 pm Peabody 217 Friday 3-3:50pm Peabody 217.
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.
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
Test Preparation Strategies
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 1 1.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 1 1.
MAT 331 Mathematical solving problem with computers.
COMP 111 Programming Languages 1 First Day. Course COMP111 Dr. Abdul-Hameed Assawadi Office: Room AS15 – No. 2 Tel: Ext. ??
CompSci 102 Spring 2012 Prof. Rodger January 11, 2012.
COMP Introduction to Programming Yi Hong May 13, 2015.
Analysis CS 367 – Introduction to Data Structures.
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.
Great Theoretical Ideas in Computer Science.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Catie Welsh January 10, 2011 MWF 1-1:50 pm Sitterson 014.
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)
Greedy Algorithms And Genome Rearrangements
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
Andrew’s Leap 2011 Pancakes With A Problem Steven Rudich.
Matter and Interactions 1 Fall 2006 Matter & Interactions I Physics Professor & Lecturer: Dr. Reinhard Schumacher Teaching Assistants: Ms. Elisa.
June 19, Liang-Jun Zhang MTWRF 9:45-11:15 am Sitterson Hall 011 Comp 110 Introduction to Programming.
Chapter 7 The Practices: dX. 2 Outline Iterative Development Iterative Development Planning Planning Organizing the Iterations into Management Phases.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
CSCE 1030 Computer Science 1 First Day. Course Dr. Ryan Garlick Office: Research Park F201 B –Inside the Computer Science department.
Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2005 Lecture 3 Jan 18, 2005 Carnegie Mellon University.
Warm-up: Take a minute to identify the “tone words” that you are struggling with the most or that you would like to review today. We will be making a list.
BIT 143: Programming – Data Structures It is assumed that you will also be present for the slideshow for the first day of class. Between that slideshow.
1 CS 381 Introduction to Discrete Structures Lecture #1 Syllabus Week 1.
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.
Introduction to Structures CSLU 1100.Lo3 Fall 2007 Cameron McInally Fordham University.
Spring 2008 Mark Fontenot CSE 1341 – Honors Principles of Computer Science I Note Set 1 1.
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
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.
Pancakes With A Problem!
Lectures on Network Flows
September 27 – Course introductions; Adts; Stacks and Queues
Pancakes With A Problem!
Cooking for Computer Scientists.
Bounds for Sorting by Prefix Reversal -- Pancake Problem
COMP 122 – Design and Analysis of Algorithms
Presentation transcript:

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 may be injured. I hereby assume all the risk described above, even if Luis von Ahn, his TAs or agents, through negligence or otherwise, otherwise be deemed liable. I hereby release, waive, discharge covenant not to sue Luis von Ahn, his TAs or any agents, participants, sponsoring agencies, sponsors, or others associated with the event, and, if applicable, owners of premises used to conduct the pancake cooking event, from any and all liability arising out of my participation, even if the liability arises out of negligence that may not be foreseeable at this time. Please don’t burn yourself…

Administrative Crapola

Check this Website OFTEN!

Course Staff Instructors Luis von Ahn Anupam Gupta TAs Yifen Huang Daniel Nuffer Daniel Schafer

Homework 40% Final 25% In-Class Quizzes 5% 3 In-Recitation Tests 25% Participation 5% If Suzie gets 60,90,80 in her tests, how many total test points will she have in her final grade? (0.05)(60) + (0.10)(90) + (0.10)(80) = 20 Lowest homework grade is dropped Lowest test grade is worth half Grading

Weekly Homework Ten points per day late penalty No homework will be accepted more than three days late Homework will go out every Tuesday and is due the Tuesday after

Assignment 1: The Great 251 Hunt! You will work in randomly chosen groups of 4 The actual Puzzle Hunt will start at 8pm tonight You will need at least one digital camera per group Can buy a digital camera for $8 nowadays!

Shared Secret

Collaboration + Cheating You may NOT share written work You may NOT use Google, or solutions to previous years’ homework You MUST sign the class honor code

Textbook There is NO textbook for this class We have class notes in wiki format You too can edit the wiki!!!

((( ))) Feel free to ask questions

Lecture 1 (August 28, 2007) Pancakes With A Problem!

He does this by grabbing several from the top and flipping them over, repeating this (varying the number he flips) as many times as necessary The chefs at our place are sloppy: when they prepare pancakes, they come out all different sizes When the waiter delivers them to a customer, he rearranges them (so that smallest is on top, and so on, down to the largest at the bottom)

Developing A Notation: Turning pancakes into numbers

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

4 Flips Are Sufficient

Best Way to Sort X = Smallest number of flips required to sort: ?  X  ? Upper Bound Lower Bound 4

Four Flips Are Necessary Flip 2 must bring 4 to top (if it didn’t, we would spend more than 3) Flip 1 has to put 5 on bottom If we could do it in three flips:

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

MAX over s 2 stacks of 5 of MIN # of flips to sort s P 5 = X1X1 X2X2 X3X3 X 119 X th Pancake Number Number of flips required to sort the worst case stack of 5 pancakes P 5 =

5 th Pancake Number ?  P 5  ? Upper Bound Lower Bound 4

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 =

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

Initial Values of P n n3012 PnPn 0013

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

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

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

?  P n  ? Try to find 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

?  P n  2n-3

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 ?

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

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

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

n  P n  2n – 3 for n > 3 Bring-to-top is within a factor of 2 of optimal!

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

Can you find a faster way than 2P n flips to go from ANY to ANY? ((( )))

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

The Known Pancake Numbers n PnPn

P 14 is Unknown 1  2  3  4  …  13  14 = 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 Sorting By Prefix Reversal

(17/16)n  P n  (5n+5)/3 William Gates and 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 and H. I. Sudborough. On the Diameter of the Pancake Network. Journal of Algorithms, vol 25, pp 67-94, 1997.

How many different stacks of n pancakes are there? n! = 1 x 2 x 3 x … x n

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

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

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

Mutation Distance

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

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 Today’s lecture is a microcosm of this exercise

Definitions of: n th pancake number lower bound upper bound Proof of: ANY to ANY in ≤ P n Important Technique: Bracketing Here’s What You Need to Know…