GATE 2022
65 questions
MCQ 32 · MSQ 15 · NAT 181-mark 30 · 2-mark 35
Questions 11–15 of 65
Which one of the following statements is TRUE for all positive functions ?
Answer: (A)
(A) Let be a polynomial with (it must be positive for large ). Then and . The ratio , a positive constant, so . This is true.
(B) For , . The two are equal, not strictly smaller, so fails.
(C) For , and . grows much faster, so fails.
(D) For , is far smaller than , so fails.
Answer: (A)
(B) For , . The two are equal, not strictly smaller, so fails.
(C) For , and . grows much faster, so fails.
(D) For , is far smaller than , so fails.
Answer: (A)
Which one of the following regular expressions correctly represents the language of the finite automaton given below?
Answer: (D)
The start state is not a final state. Look at the moves from the start state:
- On a, the machine goes to the upper final state. This state loops on b and goes back to the start on b. One full round trip is .
- On b, the machine goes to the lower final state. This state loops on a and goes back to the start on a. One full round trip is .
So the machine can make any number of round trips . Then it ends in one of the final states, with or .
This is .
Answer: (D)
- On a, the machine goes to the upper final state. This state loops on b and goes back to the start on b. One full round trip is .
- On b, the machine goes to the lower final state. This state loops on a and goes back to the start on a. One full round trip is .
So the machine can make any number of round trips . Then it ends in one of the final states, with or .
This is .
Answer: (D)
Which one of the following statements is TRUE?
Answer: (D)
Let us check each statement one by one:
- LALR(1) joins LR(1) states that have the same core. This joining can bring in a new reduce-reduce conflict so the statement is FALSE.
- The symbol table is used in almost all phases, such as semantic analysis, code generation, so the statement is FALSE.
- Data flow analysis is used for code optimization. It is not used for run-time memory management so the statement is FALSE.
- Each deterministic CFL has an LR(1) grammar. So LR(1) parsing is enough for DCFLs so the statement is TRUE.
Answer: LR(1) parsing is sufficient for deterministic context-free languages
- LALR(1) joins LR(1) states that have the same core. This joining can bring in a new reduce-reduce conflict so the statement is FALSE.
- The symbol table is used in almost all phases, such as semantic analysis, code generation, so the statement is FALSE.
- Data flow analysis is used for code optimization. It is not used for run-time memory management so the statement is FALSE.
- Each deterministic CFL has an LR(1) grammar. So LR(1) parsing is enough for DCFLs so the statement is TRUE.
Answer: LR(1) parsing is sufficient for deterministic context-free languages
In a relational data model, which one of the following statements is TRUE?
Answer: (A)
Let us look at each statement one by one:
- Take a relation R(A, B). The only non-trivial FDs it can have are or . In both cases the left side is a key, so R is always in BCNF this is TRUE.
- If all attributes are prime, the relation is only guaranteed to be in 3NF, not BCNF (for example ) this is FALSE.
- A relation may have no non-prime attribute (for example, when all attributes together form the key) this is FALSE.
- A BCNF decomposition does not always preserve FDs this is FALSE.
Answer: A relation with only two attributes is always in BCNF
- Take a relation R(A, B). The only non-trivial FDs it can have are or . In both cases the left side is a key, so R is always in BCNF this is TRUE.
- If all attributes are prime, the relation is only guaranteed to be in 3NF, not BCNF (for example ) this is FALSE.
- A relation may have no non-prime attribute (for example, when all attributes together form the key) this is FALSE.
- A BCNF decomposition does not always preserve FDs this is FALSE.
Answer: A relation with only two attributes is always in BCNF
Consider the problem of reversing a singly linked list. To take an example, given the linked list below,
the reversed linked list should look like
Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1) space?
the reversed linked list should look like
Which one of the following statements is TRUE about the time complexity of algorithms that solve the above problem in O(1) space?
Answer: (A)
Go through the list one time using three pointers (prev, curr, next). Reverse each link as you move:
next = currnext; currnext = prev; prev = curr; curr = next.
Every node is visited only once, and just 3 extra pointers are used. So the time is and the space is . It cannot be faster, because every link has to be changed.
Answer: The best algorithm needs time in the worst case
next = currnext; currnext = prev; prev = curr; curr = next.
Every node is visited only once, and just 3 extra pointers are used. So the time is and the space is . It cannot be faster, because every link has to be changed.
Answer: The best algorithm needs time in the worst case