Directed Acyclic graph can be used

Directed Acyclic graph can be used

Answer: C. both a and bAnswer: Directed Acyclic Graphs (DAGs) are used to represent expressions within a basic block, enabling optimization. Key ideas: Eliminate common…

  1. A.

    to generate the optimized 3 address code

  2. B.

    to eliminate the common subexpression elimination

  3. C.

    both a and b

  4. D.

    none of the above

Attempted by 290 students.

Show answer & explanation

Correct answer: C

Answer: Directed Acyclic Graphs (DAGs) are used to represent expressions within a basic block, enabling optimization.

Key ideas:

  • Eliminate common subexpressions — identical expressions are represented by a single DAG node, so repeated computations are detected and computed once.

  • Generate optimized three-address code — traverse the DAG and emit code only for distinct computations, reusing results from shared nodes to reduce temporaries and instructions.

Example:

  1. Original code: x = a + b; y = a + b;

  2. Optimized using a DAG: t1 = a + b; x = t1; y = t1

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…