chapter
    Runtime Environments and Procedure Calls PYQs for GATE CS

    Solve 2+ Runtime Environments and Procedure Calls previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2023 PYQ
    Consider the following program:

    int main()
    {
       f1();
       f2(2);
       f3();
       return(0);
    }

    int f1()
    {
       return(1);
    }

    int f2(int X)
    {
       f3();
       if (X==1)
          return f1();
       else
          return (X*f2(X-1));
    }

    int f3()
    {
       return(5);
    }

    Which one of the following options represents the activation tree corresponding to the main function?
    Question 2
    2021 Slot Set1 PYQ
    Consider the following statements.

    The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
    The sequence of procedure returns corresponds to a postorder traversal of the activation tree.

    Which one of the following options is correct?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Runtime Environments and Procedure Calls PYQs for GATE CS

    Solve 2+ Runtime Environments and Procedure Calls previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Activation Trees vs Call Graphs

    Activation Trees vs Call Graphs
    An activation tree represents the dynamic execution of a program, whereas a call graph represents the static structure of the code. A call graph has exactly one node for each unique procedure defined in the source code. An activation tree has one node for every single time a procedure is invoked during a specific run. If a recursive function calls itself five times, the call graph shows one node with a self-referential edge, but the activation tree shows five distinct nodes arranged in a parent-child hierarchy.
    Explain this more simply
    Think of a call graph as a blueprint of a factory. It shows which rooms exist and which doors connect them. An activation tree is the log of a specific day's production. If a worker walks through the same door ten times, the blueprint does not change, but the daily log records ten separate entries.
    Go one level deeper
    The activation tree is a strict tree with no cycles and a single root because execution is strictly nested. A call graph is a directed graph that may contain cycles and multiple entry points. The depth of the activation tree at any point equals the current call stack depth.

    Rules for Constructing Activation Trees

    Execution Trace

    To construct an activation tree from source code, follow a strict top-down execution trace. Begin with the main procedure as the root node. When a procedure P calls procedure Q, draw a directed edge from the current active node of P to a new child node representing this specific invocation of Q. The new node becomes the current active node. When Q returns, the active node reverts to the caller P. Repeat this for every function call in the execution order.

    Core Rules

    • One node per invocation, not per function name.
    • Edges represent the caller-callee relationship.
    • Active node shifts down on call, up on return.
    Explain this more simply
    Imagine you are drawing a family tree, but instead of generations, you are tracking phone calls. If Alice calls Bob, Bob is a child of Alice. If Bob then calls Charlie, Charlie is a child of Bob. When Bob hangs up, you go back to Alice. You never draw two Bobs as the same person if he makes two separate calls. Each call is a new node.
    Go one level deeper
    The standard method breaks if you attempt to draw the tree based on source code layout rather than execution order. The tree must reflect the dynamic sequence of calls, meaning conditional branches that evaluate to false produce no child nodes. The tree is a record of actual events, not potential ones.

    Runtime Environments and Procedure Calls: Solved Questions with Step-by-Step Explanations (2 Problems)

    Question 1 · Compiler Design · 2023 MCQ
    Consider the following program:

    int main()
    {
       f1();
       f2(2);
       f3();
       return(0);
    }

    int f1()
    {
       return(1);
    }

    int f2(int X)
    {
       f3();
       if (X==1)
          return f1();
       else
          return (X*f2(X-1));
    }

    int f3()
    {
       return(5);
    }

    Which one of the following options represents the activation tree corresponding to the main function?
    1. A. mainf1f2f3f3f2f3f1
    2. B. mainf1f2f3f3f1
    3. C. mainf1f2f3f1
    4. D. mainf1f2f3f3f2f1
    Question 2 · Compiler Design · 2021_Set1 MCQ
    Consider the following statements.

    The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
    The sequence of procedure returns corresponds to a postorder traversal of the activation tree.

    Which one of the following options is correct?
    1. A.

      is true and is false

    2. B.

      is false and is true

    3. C.

      is true and is true

    4. D.

      is false and is false

    More previous year questions (pyqs) in this unit