GATE 2014 (Session 1)
65 questions
MCQ 40 · NAT 251-mark 30 · 2-mark 35
Questions 21–25 of 65
Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time of Depth First Search on G, when G is represented as an adjacency matrix?
Answer: (C)
When the graph is stored as an adjacency matrix, the neighbours of a vertex are found by reading its full row of n entries. DFS repeats this scan for each vertex, so the total work is .
Answer:
Answer:
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of sub trees having exactly 4 nodes is . Then the value of a+10b is_______
Answer: 1
Do a post-order traversal. It finds the size of every subtree (1 + left size + right size) and counts the subtrees of size 4 on the way. The total time is .
Write the bound in the given form: a = 1, b = 0 a + 10b = 1
Answer: 1
Write the bound in the given form: a = 1, b = 0 a + 10b = 1
Answer: 1
Consider the directed graph given below.
Which one of the following is TRUE?
Which one of the following is TRUE?
Answer: (C)
The edges are: P Q, P R, R Q, S R, S Q. P and S have no incoming edges, so either one can come first. R must come before Q.
PSRQ and SPRQ are both valid orderings. PQRS is not valid, because Q comes before R.
Answer: Both PSRQ and SPRQ are topological orderings
PSRQ and SPRQ are both valid orderings. PQRS is not valid, because Q comes before R.
Answer: Both PSRQ and SPRQ are topological orderings
Let P be a quick sort program to sort numbers in ascending order using the first element as the pivot. Let t1 and t2 be the number of comparisons made by P for the inputs [1 2 3 4 5] and [4 1 5 3 2] respectively. Which one of the following holds?
Answer: (C)
Check each case:
- Sorted input [1 2 3 4 5]: every split is as uneven as possible, so 4 + 3 + 2 + 1 = 10 comparisons.
- Input [4 1 5 3 2]: pivot 4 takes 4 comparisons [2 1 3] and [5]; pivot 2 takes 2 comparisons [1] and [3]. Total 6.
Answer:
- Sorted input [1 2 3 4 5]: every split is as uneven as possible, so 4 + 3 + 2 + 1 = 10 comparisons.
- Input [4 1 5 3 2]: pivot 4 takes 4 comparisons [2 1 3] and [5]; pivot 2 takes 2 comparisons [1] and [3]. Total 6.
Answer:
Which one of the following is TRUE?
Answer: (C)
(C) A DFA with 3 states counts the number of 's modulo 3 (an keeps the state). It accepts in the state for remainder 1. So the language with 's is regular.
(A) : with pumping length , take . The pumped part lies in the 's, so pumping changes only the number of 's and the counts no longer match. Not regular.
(B) Prime length: take with prime. The pumped part is with . Pumping with gives length . Both factors are at least 2, so the length is not prime. Not regular.
(D) : the prefixes are pairwise distinguishable. With the suffix , the string is in the language. For , has two 1s, so would have to be with , which needs . So it is not in the language. A DFA would need infinitely many states. Not regular.
Answer: (C)
(A) : with pumping length , take . The pumped part lies in the 's, so pumping changes only the number of 's and the counts no longer match. Not regular.
(B) Prime length: take with prime. The pumped part is with . Pumping with gives length . Both factors are at least 2, so the length is not prime. Not regular.
(D) : the prefixes are pairwise distinguishable. With the suffix , the string is in the language. For , has two 1s, so would have to be with , which needs . So it is not in the language. A DFA would need infinitely many states. Not regular.
Answer: (C)