1 / 15

Algorithms Midterm 2011

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. HSR(99,4) <= 7 is true HSR(99,4) <= 6 is false HSR(56,3) <= 7 is true

raheem
Télécharger la présentation

Algorithms Midterm 2011

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms Midterm 2011 Karl Lieberherr

  2. 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. • HSR(99,4) <= 7 is true • HSR(99,4) <= 6 is false • HSR(56,3) <= 7 is true • 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.

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

  4. 1000*n + n^2 = 2 * n^2 n =0 and n = 1000 Only highest degree counts.

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

  6. Decimal approximation 1000 * log(10000) =

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

  8. 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)

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

  10. 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’.

  11. 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’)

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

  13. 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)

  14. 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)

  15. Question 7: TentGraph Cartesian Product

More Related