chapter
    Runtime Environments and Procedure Calls Notes for GATE CS

    Runtime Environments and Procedure Calls notes for GATE CS: 20 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questio

    runtime environments and procedure calls notes

    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.

    Building the Tree for the Anchor Example

    Consider a program where main calls A(2). Function A(int n) calls B(), and then conditionally calls A(n-1) if n > 1. Function B() calls C(), and C() simply returns. Construct the activation tree for this execution.
    The immediate instinct is to draw main, then A, then B, then C, and then another A, all in a single flat list or merging the two A calls into one node because they share the same name.
    Merging the two A calls violates the definition of an activation tree, which requires a distinct node per invocation. Furthermore, placing them flat ignores the nesting. A(n-1) is called by A(2), so it must be a child of the A(2) node, not a sibling.
    1. Start with root node: main.
    2. main calls A(2). Add child node A(2) under main. Active node is A(2).
    3. A(2) calls B(). Add child node B() under A(2). Active node is B().
    4. B() calls C(). Add child node C() under B(). Active node is C().
    5. C() returns. Active node reverts to B().
    6. B() returns. Active node reverts to A(2).
    7. A(2) checks n > 1 (2 > 1 is true). It calls A(1). Add child node A(1) under A(2). Active node is A(1).
    8. A(1) calls B(). Add child node B() under A(1).
    9. This second B() calls C(). Add child node C() under the second B().
    10. C() returns, B() returns, A(1) checks n > 1 (1 > 1 is false), A(1) returns, A(2) returns, main returns.
    Verification: The tree has main at the root. A(2) is the child of main. A(2) has two children: the first B() and A(1). The first B() has child C(). A(1) has child B(), which in turn has child C().

    17 more cards in this chapter

    Free preview ends here

    Login to view the complete notes

    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 Notes for GATE CS

    Runtime Environments and Procedure Calls notes for GATE CS: 20 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    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.

    Building the Tree for the Anchor Example

    Consider a program where main calls A(2). Function A(int n) calls B(), and then conditionally calls A(n-1) if n > 1. Function B() calls C(), and C() simply returns. Construct the activation tree for this execution.
    The immediate instinct is to draw main, then A, then B, then C, and then another A, all in a single flat list or merging the two A calls into one node because they share the same name.
    Merging the two A calls violates the definition of an activation tree, which requires a distinct node per invocation. Furthermore, placing them flat ignores the nesting. A(n-1) is called by A(2), so it must be a child of the A(2) node, not a sibling.
    1. Start with root node: main.
    2. main calls A(2). Add child node A(2) under main. Active node is A(2).
    3. A(2) calls B(). Add child node B() under A(2). Active node is B().
    4. B() calls C(). Add child node C() under B(). Active node is C().
    5. C() returns. Active node reverts to B().
    6. B() returns. Active node reverts to A(2).
    7. A(2) checks n > 1 (2 > 1 is true). It calls A(1). Add child node A(1) under A(2). Active node is A(1).
    8. A(1) calls B(). Add child node B() under A(1).
    9. This second B() calls C(). Add child node C() under the second B().
    10. C() returns, B() returns, A(1) checks n > 1 (1 > 1 is false), A(1) returns, A(2) returns, main returns.
    Verification: The tree has main at the root. A(2) is the child of main. A(2) has two children: the first B() and A(1). The first B() has child C(). A(1) has child B(), which in turn has child C().

    Drawing the Tree for Sequential Calls

    Given the following code snippet, which option correctly describes the structure of its activation tree?
    void X() { Y(); } void Y() { Z(); } void Z() {} int main() { X(); return 0; }
    TIME: 60s FORMAT: MCQ

    More notes in this unit