Skip to content
Related Articles

Related Articles

Improve Article

Data Structures and Algorithms | Set 20

  • Difficulty Level : Basic
  • Last Updated : 27 Mar, 2017

Following questions have asked in GATE CS 2006 exam.

1. Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and S is polynomial-time reducible to R. Which one of the following statements is true?
(A) R is NP-complete
(B) R is NP-hard
(C) Q is NP-complete
(D) Q is NP-hard

Answer (B)
(A) Incorrect because R is not in NP. A NP Complete problem has to be in both NP and NP-hard.
(B) Correct because a NP Complete problem S is polynomial time educable to R.
(C) Incorrect because Q is not in NP.
(D) Incorrect because there is no NP-complete problem that is polynomial time Turing-reducible to Q.

2) A set X can be represented by an array x[n] as follows:

Consider the following algorithm in which x,y and z are Boolean arrays of size n:

algorithm zzz(x[] , y[], z [])
   int i;
   for (i=O; i<n; ++i)
     z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i])

The set Z computed by the algorithm is:
(A) (X Intersection Y)
(B) (X Union Y)
(C) (X-Y) Intersection (Y-X)
(D) (X-Y) Union (Y-X)

Answer (D)
The expression x[i] ^ ~y[i]) results the only 1s in x where corresponding entry in y is 0. An array with these set bits represents set X – Y
The expression ~x[i] ^ y[i]) results the only 1s in y where corresponding entry in x is 0. An array with these set bits represents set Y – X.
The operator “V” results in Union of the above two sets.

3. Consider the following recurrence:

Which one of the following is true?
(A) T(n) = Θ(loglogn)
(B) T(n) = Θ(logn)
(C) T(n) = Θ(sqrt(n))
(D) T(n) = Θ(n)

Answer (B)

  Let n = 2^m
  T(2^m) = T(2^(m/2)) + 1
  Let T(2^m) =  S(m)
  S(m)  = 2S(m/2) + 1  

Above expression is a binary tree traversal recursion whose time complexity is Θ(m). You can also prove using Master theorem.

S(m)  = Θ(m)  
      = Θ(logn)  /* Since n = 2^m */

Now, let us go back to the original recursive function T(n)

  T(n)  = T(2^m) = S(m)
                 = Θ(Logn)

Please note that the solution of T(n) = T(√n) + 1 is Θ(Log Log n), above recurrence is different, it is T(n) = 2T(√n) + 1

Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :