HSR Help

advertisement
HSR Help
Karl Lieberherr
1/23/2011
Asymptotic Growth
1
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
2
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
3
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
4
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
2
3
4
5
6
7
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
5
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
2
3
4
5
6
7
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
3
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
6
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
7
Magic for now
HSR(11,2)=4
M(2,4)=11
*
HSR(4,1)=3
M(1,3)=4
HSR(7,2)=3
M(2,3)=7
*
*
*
*
*
*
*
*
*
0 1 2 3 4 5 6 7 8 9 10
1/23/2011
Asymptotic Growth
HSR(3,1)=2, M(1,2)=3
HSR(4,2)=2
M(2,2)=4
8
HSR(11,2)=4
M(2,4)=11
M(k,q)=n
*
*
*
*
*
*
0
*
*
*
*
*
*
4
*
*
*
4 choose 2 = 6
4 choose 1 = 4
4 choose 0 = 1
*
*
*
8
*
*
*
*
*
*
*
*
*
*
Claim:
For all k,q (k<=q):
M(k,q) = Sum[i=0 to k](q choose i)
11 = sum= M(2,4)
1/23/2011
Asymptotic Growth
9
n rungs:
0,1,2,3, … ,n-1
HSR Question
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
10
Definition of M
• M(0,q): 0 jars to break
• M(k,k): k jars to break and q=k questions to
ask: use binary search.
recurrence:
M(k,q) = M(k-1,q-1) + M(k,q-1)
M(0,q) = 1
M(k,k) = 2k
1/23/2011
Asymptotic Growth
11
M = SF
M ~ Modified Pascal
SF ~ Sum Formula
M(k,q)) = M(k-1,q-1) + M(k,q-1)
M(0,q) = 1
M(q, q) = 2^q
SF(k,q) = Sum[i=0 to k](q choose i) in Theta(q^k)
SF has the following properties:
(1) SF(0,q) = q choose 0 = 1 = M(0,q)
(2) SF(q, q) = Sum[i=0 to q] q choose i = 2^q = M(q, q)
(3) SF(k, q) = SF(k-1, q-1) + SF(k,q-1)
1/23/2011
Asymptotic Growth
12
3rd property (Ahmed)
SF(X-1, Y-1) + SF(X-1, Y)
= Sum[i=0 to Y-1] X-1 choose i + Sum[i=0 to Y] X-1 choose i
= Sum[i=0 to Y-1] X-1 choose i + Sum[i=1 to Y] X-1 choose i + X-1 choose 0
= Sum[i=0 to Y-1] X-1 choose i + Sum[i=0 to Y-1] X-1 choose (i+1) + 1
= Sum[i=0 to Y-1] ( X-1 choose i + X-1 choose (i+1) ) + 1
= Sum[i=0 to Y-1] ( X choose (i+1) ) + 1
= Sum[i=0 to Y-1] ( X choose (i+1) ) + X choose 0
= Sum[i=1 to Y] ( X choose i ) + X choose 0
= Sum[i=0 to Y] ( X choose i ) = SF(X, Y)
Therefore, SF(X,Y) = M(X,Y).
X=q ,Y=k, switch X and Y
1/23/2011
Asymptotic Growth
13
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
14
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
15
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
16
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
2
3
4
5
6
7
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
17
HSR Asymptotic Growth
M: maximum
number of rungs
questions asked: q
0
1
2
3
4
5
6
7
1/23/2011
0
1
n rungs:
0,1,2,3, … ,n-1
jars to break: k
1
2
1
3
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
18
n rungs:
0,1,2,3, … ,n-1
HSR Iterative
M: maximum
number of rungs
questions asked: q
0
1
1 4 11
1 5 16
1 b
c
1 b+1 b+1+c
1/23/2011
0
1
jars to break: k
1
2
1
12
11
134
121
13 3 1
14 7 8
14 6 41
1 5 11 15 16
1 6 16 26 31 32
1 7 22 42 57 63 64
1 8 29 64 99 120 127 128
Asymptotic Growth
19
• What is the running time of our decision tree
construction algorithm?
• Input: (n,k), k<=n
• Output: decision tree of minimum depth that
correctly determines the highest safe rung for
a ladder with rungs 0..n-1 and k jars to break.
• Algorithm:
– Construct slice of modified Pascal Triangle
– Determine tree structure from Pascal Triangle
– Fill in rung questions internal to tree
• What is its asymptotic running time?
1/23/2011
Asymptotic Growth
20
Claim
• Alice claims: she can construct DT(n,k) in time
O(f(n,k)).
• Express bound as a function of output size.
1/23/2011
Asymptotic Growth
21
Download