Pancakes With A Problem! - PowerPoint PPT Presentation

About This Presentation
Title:

Pancakes With A Problem!

Description:

CS 15-251 Fall 2006 Anupam Gupta Carnegie Mellon University Aug 29th, 2OO6 Lecture 1 Pancakes With A Problem! Fall 06 Course Staff Profs: Anupam Gupta John ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 69
Provided by: StevenR160
Learn more at: http://www.cs.cmu.edu
Category:

less

Transcript and Presenter's Notes

Title: Pancakes With A Problem!


1
Pancakes With A Problem!
Great Theoretical Ideas In Computer Science Great Theoretical Ideas In Computer Science Great Theoretical Ideas In Computer Science
Anupam Gupta CS 15-251 Fall 2006
Lecture 1 Aug 29th, 2OO6 Carnegie Mellon University
2
Fall 06 Course Staff
  • Profs Anupam Gupta
  • John Lafferty
  • TAs Albert Sheu
  • Andreas Krause
  • Todd Phillips
  • Webpage http//www.cs.cmu.edu/15251
  • Bboard academic.cs.15-251
  • Please check the webpages and Bboards regularly!

3
Read the Course Document!
Lowest homework grade is dropped
Lowest test grade is worth half
If Suzie gets 60,90,80 in her tests, how many
total test points will she have in her final
grade?
((½ 60) 90 80) (30/250) 24
4
Homework
Homework will go out every Tuesday and is due the
Tuesday after.
Seven points per day late penalty
No homework will be accepted more than seven days
late
Any written answers must be typset and given as a
PDF file.
HOMEWORK 1 IS OUT TODAY!
5
Extra Credit Tokens
Each correct solution to an Extra Credit problem
gives you a token
Each token is worth
A) One problem (up to 20 points) on a subsequent
assignment.
or B) One late submission up to 3 days late on
a subsequent assignment without any penalty.
You have to explicitly tell us when you are
using your token.
6
Clarifications?
To use option A, your HW submission must say I
am using one token for problem XYZ (worth at most
20 pts).
  • To use option B, your HW submission must still be
    at most 7 days late, and must say something like
    I am using one token for this late submission,
    which is N days late. We then only take off
    (N-3) 7 points.

7
Collaboration Cheating
You may NOT share written work
You may NOT use Google, or solutions to previous
years homework
You MUST read and sign the class honor code
(last page of Course Document).
8
Textbook
There is NO textbook for this class
Students from previous years tell us that its
imperative to come to class
9
((( )))
Feel free to ask questions
10
Pancakes With A Problem!Lecture 1 Aug 29th, 2OO6
11
The chef at our place is sloppy when he prepares
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)
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
12
Developing A NotationTurning pancakes into
numbers
5
52341
2
3
4
1
13
How do we sort this stack?How many flips do we
need?
52341
14
How many flips suffice?
52341
15
4 Flips Are Sufficient
12345
52341
43215
23415
14325
16
Best Way to Sort
52341
X Smallest number of flips required to
sort
Lower Bound
4
? ? X ? ?
Upper Bound
17
Four Flips Are Necessary
52341
41325
14325
Flip 1 has to put 5 on bottom
Flip 2 must bring 4 to top (if it didnt, we
would spend more than 3)
18
4 ? X ? 4
Upper Bound
Lower Bound
19
Our First Theorem
  • One can sort in 4 flips.

52341
20
Food for thought
  • Can every stack of 5 pancakes be sorted in 4
    flips?

How difficult can the cook make things for the
waiter?
21
Two adversaries
  • If the cook chose the worst possible stack of 5
    pancakes
  • and
  • the waiter sorted it in thefewest possible
    flips,
  • how many flips would it take?

22
5th Pancake Number
The least number of flips required to sort the
worst case stack of 5 pancakes.
P5
Upper Bound
? ? P5 ? ?
Lower Bound
23
5th Pancake Number
The least number of flips required to sort the
worst case stack of 5 pancakes.
P5
Upper Bound
4 ? P5 ? ?
Lower Bound
24
The 5th Pancake Number The MAX of the Xs
52341
54 3 2 1
1 2 3 4 5
j
120
1
199
3
2
. . . . . . .
X120
X1
Xj
X2
X3
X119
the fewest number of flips to sort stack 1 (best
strategy for waiter given this stack)
25
P5 MAX over s 2 stacks of 5 of MIN of flips
to sort s
12345
5 4 3 2 1
120
199
3
52341
. . . . . . . . . .
X120
0
4
1
X3
X119
26
Pn The least number of flips required to sort
the worst-case stack of n pancakes.
27
Pn The least number of flips required to sort
the worst-case stack of n pancakes.
a, not the
28
What is Pn for small n?
Can you do n 0, 1, 2, 3 ?
29
Initial Values of Pn
n
3
0
1
2
Pn
0
0
1
3
30
P3 3
requires 3 Flips, hence
P3 3
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
31
BracketingWhat are the best lower and upper
bounds that I can prove?
32
? ? Pn ? ?
Take a few minutes to try and prove upper and
lower bounds on Pn,for n gt 3.
33
Bring-to-top Method
Bring biggest to top Place it on bottom Bring
next largest to topPlace second from bottom And
so on
34
Upper Bound On PnBring-to-top Method For n
Pancakes
  • If n1, 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
35
Better Upper Bound On PnBring-to-top Method For
n Pancakes
  • If n2, 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
36
? ? Pn ? 2n-3
37
  • Given any stack, does Bring-to-Topdo the fewest
    flips possiblefor this given stack?

38
No. Bring-to-top not always optimal for a
particular stack
32145
52341
23145
41325
14325
  • Bring-totop takes 5 flips,
  • but we can do in 4 flips

39
? ? Pn ? 2n-3
What other bounds can you prove on Pn?
40
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
41
n ? Pn
S
2468..n135..n-1
Suppose n is even
S contains n pairs that will need to be broken
apart during any sequence that sorts it
21
Detail This construction only works when ngt2
42
n ? Pn
S
1357..n246..n-1
Suppose n is odd
S contains n pairs that will need to be broken
apart during any sequence that sorts it
132
Detail This construction only works when ngt3
43
n ? Pn ? 2n 3 for n gt 3
Bring-to-top is within a factor of 2 of optimal!
44
From ANY stack to sorted stack in Pn
From sorted stack to ANY stack in Pn ?
Reverse the sequences we use to sort
Hence, from ANY stack to ANY stack in 2Pn
45
From ANY stack to ANY stack in 2Pn.
Can you find a faster way than 2Pn flips to go
from ANY to ANY?
46
ANY Stack S to ANY stack T in Pn
3,5,1,2,4
1,2,3,4,5
new T
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
47
The Known Pancake Numbers
Pn
n
  • 01345

12345678910111213
7891011131415
48
P14 is Unknown
1?2?3?4??13?14 14! orderings of 14 pancakes
14! 87,178,291,200
49
Is This Really Computer Science?
50
Sorting By Prefix Reversal
Posed in Amer. Math. Monthly 82 (1) (1975),
Harry Dweighter a.k.a. Jacob Goodman
51
(17/16)n ? Pn ? (5n5)/3
William H. Gates and Christos Papadimitriou.
Bounds For Sorting By Prefix Reversal. Discrete
Mathematics, vol 27, pp 47-57, 1979.
52
(15/14)n ? Pn ? (5n5)/3
H. Heydari and H. I. Sudborough. On the Diameter
of the Pancake Network. Journal of Algorithms,
vol 25, pp 67-94, 1997.
53
How many different stacks of n pancakes are there?
n! 1 x 2 x 3 x x n
54
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 5 3 2 4 1
  • 54321 120 possible permutations on S

55
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.

56
A Permutation is a NOUN.A permutation can also
be a VERB.
  • 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.

57
There are n! permutations of n elements.
n! 1 x 2 x 3 x x n
58
Pancake NetworkDefinition 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
59
Network For n3
213
123
312
321
132
231
60
Network For n4
61
Pancake NetworkMessage Routing Delay
  • What is the maximum distance between two nodes in
    the network?

Pn
62
Pancake NetworkReliability
  • 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.
63
Mutation Distance
64
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.

65
One Simple Problem
A host of problems and applications at the
frontiers of science
66
Study Bee
  • Please read the course document carefully.
  • You must hand in asigned collaboration policy
    page.

67
Study Bee
  • Definitions of
  • nth pancake number
  • lower bound
  • upper bound
  • permutation
  • Proof of
  • ANY to ANY in Pn
  • Important Technique
  • Bracketing

68
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
    he Pancake Network. Journal of Algorithms, vol
    25, pp 67-94, 1997
Write a Comment
User Comments (0)
About PowerShow.com