Algorithms Midterm 2011

advertisement
Algorithms Midterm 2011
Karl Lieberherr
Question 1
• The textbook answer: HSR(n,k) <= 2*k*n^(1/k) is
not precise enough to answer the questions.
• Need precise answer by modified Pascal Triangle.
1. HSR(99,4) <= 7 is true
– HSR(99,4) <= 6 is false
2. HSR(56,3) <= 7 is true
3. Decision tree construction based on MR
recurrence, MR(k,q) = MR(k-1,q-1) + MR(k,q-1);
MR(q,q) = 2^q;MR(0,q)=1.
Question 2a
• Alice defends 1000*n + n^2 in O(n^2).
• Alice’ claim is : Exists C,n0>0 ForAll n>n0:
1000*n + n^2 <= C*n^2.
• The refutation protocol is: Alice claims, Bob
tries to refute, Alice provides C,n0 and Bob
provides n so that 1000*n + n^2 > C*n^2.
• Bing/Wolfram|Alpha: If Alice provides C=2
and n0=1000, Bob will not be able to refute.
Next slide.
1000*n + n^2 = 2 * n^2
n =0 and n = 1000
Only highest
degree counts.
Question 2b
• Alice’ Claim: 1000*log(n) in O(n)
• Bing/Wolfram|Alpha: Alice chooses C = 1 and
n = 10000 and Bob will not be able to refute.
• Refutation protocol is the same as in 2a.
1000 * log(10000) =
Question 3
• Does graph G have an independent set of size
7?
• The algorithm tries all (n choose 7) subsets of
the n nodes. Is Theta(n^7) because (n choose
7) in Theta(n^7).
• Can use other problems/algorithms.
Question 4
• Reverse edges of graph. O(n+m)
• Do depth-first or breadth-first from v3. If you
encounter v1 or v2, stop and return true else
return false.
• O(n+m)
Question 5
• Improve the following Topological Ordering
Algorithm:
• TopologicalOrdering(G)
– Find node v with in-degree 0 and order it first.
– Recursively compute TopologicalOrdering(G-v) and
append this order after v.
Question 5 (continued)
• Need second algorithm Predec: For each node
compute the number of predecessors M: V->
non-negative int. Predec: G -> M.
• Need third algorithm IU to incrementally update
M, G when node v is deleted: IU: G,M,v -> G’,M’.
• Need fourth algorithm InitZ: M -> Z where Z is the
set of all nodes with zero predecessors in M.
• Need fifth algorithm IUWatch to watch updates
of M when v is deleted and update set Z of nodes
with 0 predecessors. IUWatch: G,M,v,Z -> G’,M’,Z’.
Question 5 (continued)
• compose algorithms
– preprocess: compose Predec: G -> M with InitZ: M -> Z.
Composition can be done more efficiently than sequential
composition. Not an asymptotic improvement.
• Around “Find a node v with in-degree 0” : “choose
element of Z”.
• IUWatch: G,M,v,Z -> G’,M’,Z’. Composing IU: G,M,v ->
G’,M’ and InitZ: M’ -> Z’ achieves the same result but
inefficiently. Composition must be done more
efficiently to achieve asymptotic improvement.
• TS(G’,M’,Z’)
Question 5 (continued)
summary
• TopologicalOrdering(G)
– Preprocess: compose Predec: G -> M with InitZ: M
-> Z.
– TopOrder(G,M,Z)
• Find node v with in-degree 0 is replaced by: choose v in
Z. Order v first.
• IUWatch: G,M,v,Z -> G’,M’,Z’.
• Recursively compute TopOrder(G’,M’,Z’) and append
this order after v.
Question 5 (continued)
analysis
• G=(V,E), |V|=n, |E|=m.
• TopologicalOrdering(G)
– Preprocess: compose Predec: G -> M with InitZ: M ->
Z. O(n+m). M[0..n-1] as array.
– TopOrder(G,M,Z)
• Find node v with in-degree 0 is replaced by: choose v in Z.
Order v first. O(1).
• IUWatch: G,M,v,Z -> G’,M’,Z’. overall: O(n+m)
• Recursively compute TopOrder(G’,M’,Z’) and append O(1)
this order after v.
– O(n+m)
Question 6
• Alice claims Bertrand’s Postulate: ForAll
natural numbers n>1 Exists a prime p: n < p <
2*n.
• Refutation protocol: Alice claims. Bob tries to
refute. Bob provides n. Alice provides p.
Refutation is successful iff
– !(prime(p) and n<p<2*n)
Question 7: Tent
Graph Cartesian Product
Download