GATE 2013
80 questions
MCQ 801-mark 38 · 2-mark 42
Questions 31–35 of 80
Consider the following function:
int unknown(int n){
int i, j, k=0;
for (i=n/2; i<=n; i++)
for (j=2; j<=n; j=j*2)
k = k + n/2;
return (k);
} The return value of the function isAnswer: (B)
Look at each part of the code:
- Outer loop: it runs n/2 + 1 times.
- Inner loop (j is doubled each time): it runs about times.
- Each pass adds n/2 to k.
So the value returned is:
Answer:
- Outer loop: it runs n/2 + 1 times.
- Inner loop (j is doubled each time): it runs about times.
- Each pass adds n/2 to k.
So the value returned is:
Answer:
What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?
Answer: (C)
The running time of Bellman-Ford is . In a complete graph, the number of edges is .
Time for n vertices:
Final answer:
Time for n vertices:
Final answer:
Consider the DFA A given below.
Which of the following are FALSE?
1. Complement of L(A) is context-free.
2. L(A) = L((11*0+0) (0+1)*0*1*)
3. For the language accepted by A, A is the minimal DFA.
4. A accepts all strings over {0, 1} of length at least 2.
Which of the following are FALSE?
1. Complement of L(A) is context-free.
2. L(A) = L((11*0+0) (0+1)*0*1*)
3. For the language accepted by A, A is the minimal DFA.
4. A accepts all strings over {0, 1} of length at least 2.
Answer: (D)
In the figure, the start state goes to a second state on 1 and to the final state on 0. The second state does the same: 1 to itself and 0 to the final state. The final state loops on 0 and 1. So A accepts exactly the strings that have at least one 0: .
- Statement 1: the complement is . This is regular, so it is context-free. True.
- Statement 2: , and (the extra adds nothing). So the expression is = L(A). True.
- Statement 3: the start state and the second state are both non-final, and both go to the second state on 1 and to the final state on 0. So they are equivalent and can be merged, which means A is not minimal. False.
- Statement 4: the string 11 has length 2 but no 0, so A rejects it. False.
The false statements are 3 and 4.
Answer: (D)
- Statement 1: the complement is . This is regular, so it is context-free. True.
- Statement 2: , and (the extra adds nothing). So the expression is = L(A). True.
- Statement 3: the start state and the second state are both non-final, and both go to the second state on 1 and to the final state on 0. So they are equivalent and can be merged, which means A is not minimal. False.
- Statement 4: the string 11 has length 2 but no 0, so A rejects it. False.
The false statements are 3 and 4.
Answer: (D)
Consider the languages and . Which one of the following represents ?
Answer: (A)
First part: (joining the empty set with any language gives the empty set).
Second part:
The union is {}
Answer: {}
Second part:
The union is {}
Answer: {}
Consider the following languages.
Which one of the following statements is FALSE?
Which one of the following statements is FALSE?
Answer: (D)
- is regular, so its complement is regular too. The statement (D) says the complement is context-free but not regular, which is false.
- (A) (with ) is the union of and . A PDA pushes the leading 0s, skips the 1s, and pops one 0 for each trailing 0. It accepts if the stack is not empty at the end (p > r), or if it runs out of 0s to pop while 0s are still left (p < r). It is a CFL. True.
- (B) every string of is in , so , a CFL. True.
- (C) is a CFL, so it is recursive. Recursive languages are closed under complement, so the complement of is recursive (even though it need not be a CFL). True.
Answer: (D)
- (A) (with ) is the union of and . A PDA pushes the leading 0s, skips the 1s, and pops one 0 for each trailing 0. It accepts if the stack is not empty at the end (p > r), or if it runs out of 0s to pop while 0s are still left (p < r). It is a CFL. True.
- (B) every string of is in , so , a CFL. True.
- (C) is a CFL, so it is recursive. Recursive languages are closed under complement, so the complement of is recursive (even though it need not be a CFL). True.
Answer: (D)