GATE 2015 (Session 2)
64 questions
MCQ 42 · NAT 221-mark 29 · 2-mark 35
Questions 26–30 of 64
Consider two decision problems such that reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to . Then which one of the following is consistent with the above statement?
Answer: (A)
3-SAT is NP-complete: it is in NP, and every problem in NP reduces to it in polynomial time. Write for "A reduces to B in polynomial time".
: convert an instance of to 3-SAT, then check a certificate for 3-SAT in polynomial time. So is in NP. Easiness moves backward along a reduction.
: every NP problem reduces to 3-SAT, and 3-SAT reduces to . Chaining the two reductions, every NP problem reduces to , so is NP hard. Hardness moves forward.
Nothing given makes NP hard or puts in NP. So (B), (C) and (D) may hold for some problems but do not follow; only (A) always holds.
Answer: (A)
: convert an instance of to 3-SAT, then check a certificate for 3-SAT in polynomial time. So is in NP. Easiness moves backward along a reduction.
: every NP problem reduces to 3-SAT, and 3-SAT reduces to . Chaining the two reductions, every NP problem reduces to , so is NP hard. Hardness moves forward.
Nothing given makes NP hard or puts in NP. So (B), (C) and (D) may hold for some problems but do not follow; only (A) always holds.
Answer: (A)
Match the following:
Answer: (C)
Each pair has a reason:
- P, Lexical analysis: the scanner is built as a DFA, and DFA minimization cuts the number of states in it. So P-2.
- Q, Parsing: the parser applies the grammar productions to the tokens and builds the production (parse) tree. So Q-4.
- R, Register allocation: variables that are live at the same time are joined in an interference graph, and coloring that graph with one color per register gives the allocation. So R-1.
- S, Expression evaluation: an expression tree is evaluated by post-order traversal, which visits both operands before the operator. So S-3.
Answer: (C)
- P, Lexical analysis: the scanner is built as a DFA, and DFA minimization cuts the number of states in it. So P-2.
- Q, Parsing: the parser applies the grammar productions to the tokens and builds the production (parse) tree. So Q-4.
- R, Register allocation: variables that are live at the same time are joined in an interference graph, and coloring that graph with one color per register gives the allocation. So R-1.
- S, Expression evaluation: an expression tree is evaluated by post-order traversal, which visits both operands before the operator. So S-3.
Answer: (C)
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?
Answer: (C)
Let us check every statement one by one:
- Option 1: in a CFG, a loop edge goes back to code that comes earlier so this is false.
- Option 2: a CFG has cycles when there are loops so this is false.
- Option 3: an AST node can have as many children as the construct needs. A CFG node (for example a switch) can have as many successors as the code has so this is true.
- Option 4: one CFG basic block can hold many statements so this is false.
Answer: The maximum number of successors depends on the input program
- Option 1: in a CFG, a loop edge goes back to code that comes earlier so this is false.
- Option 2: a CFG has cycles when there are loops so this is false.
- Option 3: an AST node can have as many children as the construct needs. A CFG node (for example a switch) can have as many successors as the code has so this is true.
- Option 4: one CFG basic block can hold many statements so this is false.
Answer: The maximum number of successors depends on the input program
Consider the basic COCOMO model where is the effort applied in person-months, is the development time in chronological months, is the estimated number of delivered lines of code (in thousands) and have their usual meanings. The basic COCOMO equations are of the form
Answer: (A)
Basic COCOMO first finds the effort from the size, then the development time from the effort:
person-months, and months.
Here are constants fixed by the project class (organic, semi-detached or embedded). The options write the powers as exp() and exp(), so (A) is this form.
(B) swaps E and D, and (C) and (D) leave KLOC out of the effort equation, though effort must grow with size.
Answer: (A)
person-months, and months.
Here are constants fixed by the project class (organic, semi-detached or embedded). The options write the powers as exp() and exp(), so (A) is this form.
(B) swaps E and D, and (C) and (D) leave KLOC out of the effort equation, though effort must grow with size.
Answer: (A)
Consider the following transaction involving two bank accounts x and y.
read(x); x:=x-50; write(x); read(y); y:=y+50; write(y)
The constraint that the sum of the accounts x and y should remain constant is that of
read(x); x:=x-50; write(x); read(y); y:=y+50; write(y)
The constraint that the sum of the accounts x and y should remain constant is that of
Answer: (B)
The rule that x + y must stay the same is an integrity constraint on the database. A transaction has to keep this rule true. This is the consistency property.
Answer: Consistency
Answer: Consistency