# Data Structures and Algorithms | Set 20

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]) ` `} ` |

*chevron_right*

*filter_none*

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.

## Recommended Posts:

- Data Structures and Algorithms | Set 33
- Data Structures and Algorithms | Set 29
- Data Structures and Algorithms | Set 28
- Data Structures and Algorithms | Set 27
- Data Structures and Algorithms | Set 32
- Data Structures and Algorithms | Set 30
- Data Structures and Algorithms | Set 31
- Data Structures and Algorithms | Set 35
- Data Structures and Algorithms | Set 34
- Data Structures and Algorithms | Set 38
- Data Structures and Algorithms | Set 26
- Data Structures and Algorithms | Set 1
- Data Structures and Algorithms | Set 17
- Data Structures and Algorithms | Set 15
- Data Structures and Algorithms | Set 14