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
    Level 3: Exam Standard
    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
    Level 3: Exam Standard
    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.

    Explore complete test series, official past papers, and chapter-wise study tools.

    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
    Correct Answer:

    A

    Step-by-Step Solution

    Insight: Trace the execution step-by-step, drawing a new node for every function invocation, especially noting the recursive call in f2.

    Exam route:

    • main calls f1, f2(2), f3. So main has 3 children: f1, f2, f3.
    • f2(2) calls f3, then since 2!=1, it calls f2(1). So f2(2) has 2 children: f3, f2(1).
    • f2(1) calls f3, then since 1==1, it calls f1. So f2(1) has 2 children: f3, f1.
    • Match this tree structure with the options. Option A matches perfectly.

    Learning route:

    1. Start at main. The code shows sequential calls: f1(), f2(2), f3(). Thus, the main node has three children in order: f1, f2, f3.
    2. Examine the first f2 invocation, f2(2). Inside f2, it first calls f3(). Then it checks X==1. Since X=2, it goes to the else branch and evaluates X*f2(X-1), which invokes f2(1). Thus, the f2 node (for X=2) has two children: f3 and f2 (for X=1).
    3. Examine the second f2 invocation, f2(1). Inside this call, it first calls f3(). Then it checks X==1. Since X=1, it evaluates return f1(), invoking f1(). Thus, this second f2 node has two children: f3 and f1.
    4. The complete activation tree is: main has children [f1, f2, f3]. The first f2 has children [f3, f2]. The second f2 has children [f3, f1].
    5. Option A depicts exactly this hierarchy. Option B misses the recursive f2 call entirely. Option D incorrectly makes f3, f2, and f1 all direct children of the first f2, ignoring the nesting of the recursive call.
    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

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: Procedure calls push frames onto the stack (preorder), and returns pop them only after all nested calls finish (postorder).

    Exam route: Recall that an activation tree's call sequence matches preorder traversal (node before children), and return sequence matches postorder traversal (children before node). Both statements are true.

    Learning route:

    1. An activation tree represents the dynamic execution of a program, where each node is a specific invocation.
    2. When a procedure P calls Q, Q becomes a child of P. The call event happens before Q executes any of its own internal calls. This perfectly matches preorder traversal, which visits a node before its children. Thus, is true.
    3. When Q finishes executing, it returns to P. This return event can only happen after all of Q's children (and their descendants) have finished and returned. This perfectly matches postorder traversal, which visits a node only after all its children have been visited. Thus, is true.
    4. Therefore, both and are true.

    More previous year questions (pyqs) in this unit