GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 106–110 of 185
Let denote the number of binary strings of length n that contain no consecutive 0s.
Which of the following recurrences does satisfy?
Which of the following recurrences does satisfy?
Answer: (D)
List the valid strings for each length. The count is written after the dash.
So . The reason: split the valid strings of length by their last bit.
- A string ending in can have any valid string of length in front of it. That gives strings.
- A string ending in must have just before that , so it ends in . In front of the can be any valid string of length . That gives strings.
The counts follow this rule, so .
The other options fail: (A) would give , but . (B) would give , but . (C) would give , but .
Answer: (D)
So . The reason: split the valid strings of length by their last bit.
- A string ending in can have any valid string of length in front of it. That gives strings.
- A string ending in must have just before that , so it ends in . In front of the can be any valid string of length . That gives strings.
The counts follow this rule, so .
The other options fail: (A) would give , but . (B) would give , but . (C) would give , but .
Answer: (D)
The subset-sum problem is defined as follows. Given a set of n positive integers,
S={} and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this problem uses a 2-dimensional Boolean array, X, with n rows and W+1 columns. X[i,j], , , is TRUE if and only if there is a subset of {}whose elements sum to j.
Which entry of the array X, if TRUE, implies that there is a subset whose elements sum to W?
Which entry of the array X, if TRUE, implies that there is a subset whose elements sum to W?
Answer: (C)
is TRUE exactly when some subset of the first i elements has sum j. We want a subset of the whole set S with sum W, so we need the row that uses all n elements and the column for the sum W. That entry is .
The other entries do not answer the question:
- uses only .
- is about sum 0, which the empty subset gives; it says nothing about W.
- leaves out and asks for sum n, not W.
Answer: (C)
The other entries do not answer the question:
- uses only .
- is about sum 0, which the empty subset gives; it says nothing about W.
- leaves out and asks for sum n, not W.
Answer: (C)
The subset-sum problem is defined as follows. Given a set of n positive integers,
S={} and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this problem uses a 2-dimensional Boolean array, X, with n rows and W+1 columns. X[i,j], , , is TRUE if and only if there is a subset of {}whose elements sum to j.
Which of the following is valid for and ?
Which of the following is valid for and ?
Answer: (B)
Look at the element when . A subset of with sum j either leaves out or uses it once.
- Leave out : the sum j must come from , which is .
- Use : the rest must give from , which is .
Either case is enough, so we take the OR:
- (A) uses , which may already contain . So it lets be used more than once, which a subset cannot do.
- (C) and (D) use AND, which would need both cases to hold together.
Answer: (B)
- Leave out : the sum j must come from , which is .
- Use : the rest must give from , which is .
Either case is enough, so we take the OR:
- (A) uses , which may already contain . So it lets be used more than once, which a subset cannot do.
- (C) and (D) use AND, which would need both cases to hold together.
Answer: (B)
Consider the following sequence of nodes for the undirected graph given below:
1.a b e f d g c
2.a b e f c g d
3.a d g e b c f
4.a d b c g e f
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they are first visited. Which of the above is/are possible output(s)?
1.a b e f d g c
2.a b e f c g d
3.a d g e b c f
4.a d b c g e f
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they are first visited. Which of the above is/are possible output(s)?
Answer: (B)
1. : Once is visited, the next node must be or (its unvisited neighbours). It goes to , which is not a neighbour of . So this traversal is not valid.
2. : are all edges. has no unvisited neighbour, so DFS goes back to , then and . This is valid.
3. : are all edges, and each step goes to an unvisited neighbour. This is valid.
4. : Once is visited, the next node must be or . It goes to , which is not a neighbour of . So this traversal is not valid.
So only and are possible.
Answer: (B)
The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is
Answer: (C)
- BFS starts at . Its neighbours must all be visited before , which is two steps away. Here comes before and , so this is wrong.
- BFS starts at . Its neighbours are , but is not one of them. So must come before . Here it does not, so this is wrong.
- Start at . Its neighbours go into the queue. Visit : joins the queue. Visit : joins the queue. Visit : nothing new. The queue now gives and then . The order is , which is a valid BFS order.
- Here is visited before , so 's new neighbour is queued before 's new neighbour . So must be visited before , and this order is wrong.
Answer: (C)