Question
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2015 answer key
Solution
Analyze the topological properties and structural constraints of Abstract Syntax Trees and Control Flow Graphs.
Evaluate the choices:
- (A) In a CFG, loops create back-edges where successor node can appear earlier in the program source than predecessor . Thus, statement A is false.
- (B) A CFG for a program with loops (e.g.,
while,for, orgoto) contains directed cycles. Thus, statement B is false.
- (C) 'The maximum number of successors of a node in an AST and a CFG depends on the input program.'
- In an AST, a node representing an -ary operator or a function call with arguments has child nodes (successors), which depends arbitrarily on the input program syntax.
- In a CFG, a basic block ending in an -way
switchstatement has successor basic blocks, which also directly depends on the input program.
Hence, statement C is true.
- (D) In a CFG, each node is typically a basic block containing multiple statements. Thus, statement D is false.
Final answer
C
Common trap
Assuming CFG nodes are restricted to at most 2 successors (as in binary if-else branches), overlooking switch statements.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 2
- Question
- 24 of 65, printed as CS Q.14
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.