Multiplicative Inverse - Efficient Algorithms and Intractable Problems - Solved Exams, Exams of Algorithms and Programming

Main points of this past exam are: Multiplicative Inverse, Multiplicative, Solution, Equation, Integer, Prime, Asymptotically, N-Bit Integ, Post Order, Order Number

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shameem_99
shameem_99 🇮🇳

4.4

(12)

58 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 170 Fall 2008 - Solutions to Midterm 1
October 14, 2008
1 1. True: nlog nn2.
2. False: limn→∞
n2
nlog n=.
3. True: 2clog2n= (2log2n)c=nc.
4. False (not always True): For f(n) = clog2n=O(log n), we have
2f(n)=ncwhich is not O(n3) for c > 3.
5. True: log100 50000 <2.5 because 1002.5= 100000 >50000; hence by
Master’s theorem, T(n) = Θ(nlog100 50000) = o(n2.5).
6. False.
7. If we apply Master’s theorem, a=b= 3 and c= 1; since logba=c,
we have T(n) = nlogn.
8. True: gcd(3,8) = 1 and in fact 31= 3.
9. True: We cannot have 4x= 1 mod 8, since then 4x= 8k+ 1, and 1
would be a multiple of 4, a contradiction.
10. True: There are approximately N/ ln(N) prime numbers N. Thus
the probability that an n-bit number is prime is approximately N/ ln(N)
N=
1
ln(N)for N= 2n. That would be ln 2
n= Θ( 1
n).
11. True.
12. True: Let ube the vertex with lowest post order number that is not
a sink. Then there exists some edge (u, v ). If vertex vis visited while
exploring u, then post[v]<post[u]; hence that cannot happen. This
means vis already visited once we begin to explore u, but then the
edge (u, v) would be a backedge, and the graph would have a cycle,
contradicting the fact that the graph is a DAG.
13. False: The graph with vertex set V={1,2,3}and edge set E=
{(1,2),(2,1),(1,3)}is a counterexample. We can have pre[1] =
1,pre[2] = 2,post[2] = 3,pre[3] = 4,post[3] = 5,post[1] = 6,
and then vertex 2 has lowest post order but the strongly connected
component {1,2}is not a sink strongly connected component, since
it has the outgoing edge (1,3) to the strongly connected component
{3}.
1
pf3

Partial preview of the text

Download Multiplicative Inverse - Efficient Algorithms and Intractable Problems - Solved Exams and more Exams Algorithms and Programming in PDF only on Docsity!

CS 170 Fall 2008 - Solutions to Midterm 1

October 14, 2008

1 1. True: n log n ≤ n^2.

  1. False: limn→∞ n

2 n log n =^ ∞.

  1. True: 2c^ log^2 n^ = (2log^2 n) c = nc.
  2. False (not always True): For f (n) = c log 2 n = O(log n), we have 2 f^ (n)^ = nc^ which is not O(n^3 ) for c > 3.
  3. True: log 100 50000 < 2 .5 because 100^2.^5 = 100000 > 50000; hence by Master’s theorem, T (n) = Θ(nlog^100 50000 ) = o(n^2.^5 ).
  4. False.
  5. If we apply Master’s theorem, a = b = 3 and c = 1; since logb a = c, we have T (n) = n log n.
  6. True: gcd(3, 8) = 1 and in fact 3−^1 = 3.
  7. True: We cannot have 4x = 1 mod 8, since then 4x = 8k + 1, and 1 would be a multiple of 4, a contradiction.
  8. True: There are approximately N/ ln(N ) prime numbers ≤ N. Thus the probability that an n-bit number is prime is approximately N/^ ln( N N^ )= 1 ln(N ) for^ N^ = 2

n. That would be ≈ ln 2 n = Θ(^

1 n ).

  1. True.
  2. True: Let u be the vertex with lowest post order number that is not a sink. Then there exists some edge (u, v). If vertex v is visited while exploring u, then post[v] < post[u]; hence that cannot happen. This means v is already visited once we begin to explore u, but then the edge (u, v) would be a backedge, and the graph would have a cycle, contradicting the fact that the graph is a DAG.
  3. False: The graph with vertex set V = { 1 , 2 , 3 } and edge set E = {(1, 2), (2, 1), (1, 3)} is a counterexample. We can have pre[1] = 1 , pre[2] = 2, post[2] = 3, pre[3] = 4, post[3] = 5, post[1] = 6, and then vertex 2 has lowest post order but the strongly connected component { 1 , 2 } is not a sink strongly connected component, since it has the outgoing edge (1, 3) to the strongly connected component { 3 }.
  1. Θ(n): If the graph has a path of length n − 1, the DFS stack may contain n vertices.
  2. O(log n): The stack space is at most O(log n), the depth of the tree.

2 1. N = 77 = pq for p = 7, q = 11. We have (p − 1)(q − 1) = 60 and d = 7−^1 mod 60. To calculate inverse of 7, we use Extended Euclid algorithm:

60 = 8 · 7 + 4 , 7 = 1 · 4 + 3 , 4 = 1 · 3 + 1.

Thus

1 = 4 − 1 · 3 = 4 − 1 · ( 7 − 1 · 4 )) = 2 · 4 + (−1) · 7 = 2 · ( 60 − 8 · 7 ) + (−1) · 7 = 2 · 60 + (−17) · 7.

Hence (−17) · 7 = 1 mod 60 and d = 7−^1 = −17 = 43 mod 60.

  1. Since gcd(3, 60) = 3 6 = 1, we cannot choose d as inverse of e.

3 1. 1, i, −1, −i.

1 i − 1 −i 1 − 1 1 − 1 1 −i 1 i

i − 1 −i

3. FFT−^1

 =^

1 4

1 −i − 1 i 1 − 1 1 − 1 1 i 1 −i

1 (^41) (^41) (^41) 4

4 1. Let u 1 ,... , uk be neighbors of u. Vertex u is on a cycle if and only if [pre(u 1 ), post(u 1 )],... , [pre(uk), post(uk)] are disjoint intervals. Proof : (⇒ part) If u is not on a cycle, then removing u partitions the graph into k subgraphs G 1 ,... , Gk such that ui ∈ V (Gi). DFS on u proceeds by first visiting u, then exploring G 1 completely, then exploring G 2 completely, and so on. Therefore pre(u 1 ) < post(u 1 ) < pre(u 2 ) < post(u 2 ) <... < pre(uk) < post(uk). (⇐ part) If [pre(ui), post(ui)] intersects [pre(uj ), post(uj )], then with- out loss of generality, we can assume pre(ui) < pre(uj ) < post(uj ) < post(uj ). This means that there is a path P from ui to uj that does not use vertex u. Therefore u is on the cycle (u, ui) + P + (uj , u).

  1. In fact, we can have a graph where u and v are in the same strongly connected component, and yet pre and post intervals of u and v are disjoint: In directed graph G = (V, E) with vertex set V = {a, b, u, v}