chapter
    Binary Trees, Binary Search Trees and Traversals PYQs for GATE CS

    Solve 13+ Binary Trees, Binary Search Trees and Traversals previous year questions for GATE CS with answers and detailed solutions. Free sample questions belo

    Try a question

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

    Question 1
    2026 Slot Set2 PYQ
    Level 3: Exam Standard
    The set T represents various traversals over binary tree. The set S represents the order of visiting nodes during a traversal.

    TS
    I: InorderL: left subtree, node, right subtree
    II: PreorderM: node, left subtree, right subtree
    III: PostorderN: left subtree, right subtree, node


    Which one of the following is the correct match from T to S ?
    Question 2
    2026 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider a binary search tree (BST) with leaf nodes (). Given any node , the key present in the node is denoted as . All the keys present in the given BST are distinct. The keys belong to the set of real numbers.
    For a node , let denote the node that is its inorder successor. If a node does not have an inorder successor, then is . As there are no duplicates, if is not , then .

    Corresponding to every leaf node that has a non-NULL , a new key with the following property is to be inserted into the BST.


    Let represent the list of all such new keys to be inserted into the BST.

    Which of the following statements is/are true?
    Question 3
    2026 Slot Set1 PYQ
    Level 3: Exam Standard

    The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 23 nodes is _________. (answer in integer)

    Question 4
    2026 Slot Set1 PYQ
    Level 3: Exam Standard
    The following sequence corresponds to the preorder traversal of a binary search tree :


    The position of the element 60 in the postorder traversal of is ______. (answer in integer)

    Note: The position begins with 1.
    Question 5
    2026 Slot Set1 PYQ
    Level 3: Exam Standard
    Let be the set of all integers from 1 to 15. Consider any order of insertion of the elements of into a binary search tree that creates a complete binary tree.

    Which one of the following elements can NEVER be the third element that is inserted?
    Question 6
    2025 Slot Set2 PYQ
    Level 3: Exam Standard

    Suppose the values 10, −4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let be the resulting binary search tree. The number of edges in the path from the node containing 19 to the root node of is ___________. (Answer in integer)

    Question 7
    2025 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in .

    Which ONE of the following is the number of nodes in that have exactly two children?
    Question 8
    2025 Slot Set1 PYQ
    Level 3: Exam Standard

    Which of the following statement(s) is/are <b>TRUE</b> for any binary search tree (BST) having distinct integers?

    Question 9
    2024 Slot Set2 PYQ
    Level 3: Exam Standard
    You are given a set of distinct integers. A binary search tree is created by inserting all elements of one by one, starting with an empty tree. The tree follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into , and you do not have access to .

    Which one of the following statements is TRUE?
    Question 10
    2023 PYQ
    Level 3: Exam Standard
    Consider the C function foo and the binary tree shown.

    typedef struct node {
       int val;
       struct node *left, *right;
    } node;

    int foo(node *p) {
       int retval;
       if (p == NULL)
          return 0;
       else {
          retval = p->val + foo(p->left) + foo(p->right);
          printf("%d ", retval);
          return retval;
       }
    }

    105113813

    When foo is called with a pointer to the root node of the given binary tree, what will it print?
    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.

    Binary Trees, Binary Search Trees and Traversals PYQs for GATE CS

    Solve 13+ Binary Trees, Binary Search Trees and Traversals previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Trees and Traversals

    Chapter Roadmap

    1. Binary Tree Structure, Height and Node Counts
    Foundational properties, node relationships, height bounds, and pointer math.
    2. Binary Search Tree Construction and Ordering
    Insertion logic, search paths, and the strict left-smaller, right-larger invariant.
    3. Tree Traversals and Recursive Processing
    Inorder, preorder, postorder, level-order, and reconstructing trees.
    4. Complete BSTs in Array Representation
    Mapping tree nodes to array indices, heap properties, and memory optimization.
    Goal: Transition from visual, pointer-based thinking to rigorous mathematical problem-solving.

    The Binary Tree: Core Definition

    The Binary Tree: Core Definition

    A binary tree is a finite set of nodes that is either empty or consists of a root node and two disjoint subsets called the left subtree and right subtree.

    Key Characteristics

    • Maximum Degree: Every node can have at most 2 children (degree 0, 1, or 2).
    • Ordered Subtrees: The left and right children are distinct. A tree with a single left child is structurally different from a tree with a single right child.
    Root L R
    Note: This ordered nature is what allows binary trees to be used for searching and sorting later in the chapter.

    Binary Trees, Binary Search Trees and Traversals: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Programming and Data Structures · 2026_Set2 MCQ
    The set T represents various traversals over binary tree. The set S represents the order of visiting nodes during a traversal.

    TS
    I: InorderL: left subtree, node, right subtree
    II: PreorderM: node, left subtree, right subtree
    III: PostorderN: left subtree, right subtree, node


    Which one of the following is the correct match from T to S ?
    1. A.

      I – L, II – M, III – N

    2. B.

      I – M, II – L, III – N

    3. C.

      I – N, II – M, III – L

    4. D.

      I – L, II – N, III – M

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: The names of the traversals (pre, in, post) directly indicate the position of the current node relative to its subtrees.

    Exam route: Preorder = Node first (pre). Inorder = Node in the middle (in). Postorder = Node last (post). Match these to the given descriptions: I (Inorder) is L (left, node, right). II (Preorder) is M (node, left, right). III (Postorder) is N (left, right, node). This matches option A.

    Learning route:

    1. Depth-first traversals are defined by when the current node is processed relative to its left and right subtrees.
    2. Preorder: The prefix "pre" means the node is visited before its subtrees. Order: Node, Left, Right (M).
    3. Inorder: The prefix "in" means the node is visited in between its left and right subtrees. Order: Left, Node, Right (L).
    4. Postorder: The prefix "post" means the node is visited after both subtrees. Order: Left, Right, Node (N).
    5. Matching these definitions to the given set S yields I-L, II-M, III-N.

    Verification: Consider a tree with root A, left B, right C. Preorder visits A, then B, then C (Node, Left, Right). Inorder visits B, then A, then C (Left, Node, Right). Postorder visits B, then C, then A (Left, Right, Node). This perfectly matches M, L, N respectively.

    Question 2 · Programming and Data Structures · 2026_Set2 MSQ
    Consider a binary search tree (BST) with leaf nodes (). Given any node , the key present in the node is denoted as . All the keys present in the given BST are distinct. The keys belong to the set of real numbers.
    For a node , let denote the node that is its inorder successor. If a node does not have an inorder successor, then is . As there are no duplicates, if is not , then .

    Corresponding to every leaf node that has a non-NULL , a new key with the following property is to be inserted into the BST.


    Let represent the list of all such new keys to be inserted into the BST.

    Which of the following statements is/are true?
    1. A.

      cannot have any duplicates

    2. B.

      will have at least one element

    3. C.

      After inserting all keys from , the height of the BST can increase at most by one

    4. D.

      Number of nodes in the BST will double after inserting all keys from

    Correct Answer:

    ["A","C"]

    Step-by-Step Solution

    Insight: This is a BST structural property question, recognizable because it asks about the effect of inserting keys between a leaf and its inorder successor.

    Exam route: The inorder successor of a leaf is the next node in sorted order. The interval contains no existing tree nodes. Inserting here always makes it the right child of . Since intervals for different leaves are disjoint, all are distinct (A is true). New nodes are added at depth , so height increases by at most 1 (C is true). If , is empty (B is false). Total nodes become , which does not double (D is false).

    Learning route:

    Step 1: Analyze the insertion point. For a leaf with a non-NULL successor, is the lowest ancestor of that is greater than . Any value strictly between them will follow the exact path to and then go right, becoming the right child of .

    Step 2: Check for duplicates (Option A). In the sorted inorder sequence, and are adjacent in terms of the condition that no tree node lies between them. Thus, the open intervals for different leaves are strictly disjoint. Any chosen must be distinct. Option A is TRUE.

    Step 3: Check for empty (Option B). If the tree has node, it is a leaf, and its successor is NULL. Thus, is empty. Option B is FALSE.

    Step 4: Check height increase (Option C). The original height is . New nodes are added as right children of leaves, so their depth is . The height can increase by at most 1. Option C is TRUE.

    Step 5: Check node doubling (Option D). We add at most nodes. The new total is . For this to equal , we would need , which is impossible for any valid tree. Option D is FALSE.

    Wrong path: Assuming always, leading to the belief that must have at least one element. Or assuming "doubling" is possible by miscounting the number of leaves versus total nodes.

    Question 3 · Programming and Data Structures · 2026_Set1 NAT

    The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 23 nodes is _________. (answer in integer)

    Correct Answer:

    11.00

    Step-by-Step Solution

    Insight: This is a strict binary tree height question, recognizable because it asks for the "maximum possible height" of a "full" (strict) binary tree with a given node count.

    Exam route: A full binary tree has nodes with 0 or 2 children. To maximize height, make the tree as unbalanced as possible: each internal node has one leaf child and one internal node child. The number of internal nodes is . The max height equals the number of internal nodes. For , height = .

    Learning route:

    Step 1: Understand the constraints. A "full" or "strict" binary tree requires every node to have either 0 or 2 children. No node can have exactly 1 child.

    Step 2: Relate nodes to degrees. Let be leaves, be internal nodes (degree 2). We know and Total .

    Step 3: Calculate for .

    .

    There are exactly 11 internal nodes.

    Step 4: Maximize the height. Height is the number of edges on the longest root-to-leaf path. To make this path as long as possible, we must string the internal nodes together in a single "spine".

    Step 5: Construct the spine. Each of the 11 internal nodes (except the last one) will have one child that is a leaf (which terminates that branch) and one child that is the next internal node in the spine. The 11th internal node will have two leaf children.

    Step 6: Count the edges. The path from the root to the deepest leaf passes through all 11 internal nodes. The number of edges in this path is exactly 11.

    Formula: .

    Wrong path: Confusing "full" with "perfect". A perfect tree minimizes height (). The question asks for maximum height, which requires maximizing imbalance while respecting the strict degree constraint.

    Question 4 · Programming and Data Structures · 2026_Set1 NAT
    The following sequence corresponds to the preorder traversal of a binary search tree :


    The position of the element 60 in the postorder traversal of is ______. (answer in integer)

    Note: The position begins with 1.
    Correct Answer:

    7.00

    Step-by-Step Solution

    Insight: This is a BST reconstruction from preorder question, recognizable because it provides a preorder sequence and asks for the position of a specific node in the postorder sequence.

    Exam route: Reconstruct the BST by splitting the preorder sequence at each root: elements smaller go left, larger go right. Once the tree is built, generate the postorder traversal (Left, Right, Root) and count the 1-based index of the target element.

    Learning route:

    Step 1: Reconstruct the BST from preorder: [50, 25, 13, 40, 30, 47, 75, 60, 70, 80, 77].

    • Root is 50.
    • Left subtree (values < 50): [25, 13, 40, 30, 47].
    • Root 25. Left: [13]. Right: [40, 30, 47].
    • Root 40. Left: [30]. Right: [47].
    • Right subtree (values > 50): [75, 60, 70, 80, 77].
    • Root 75. Left: [60, 70]. Right: [80, 77].
    • Root 60. Left: []. Right: [70].
    • Root 80. Left: [77]. Right: [].

    Step 2: Verify the tree structure.

    50

    / \

    25 75

    / \ / \

    13 40 60 80

    / \ \ /

    30 47 70 77

    Step 3: Generate postorder traversal (Left, Right, Root).

    • Left subtree of 50 (root 25): 13, (30, 47, 40), 25 13, 30, 47, 40, 25.
    • Right subtree of 50 (root 75): (70, 60), (77, 80), 75 70, 60, 77, 80, 75.
    • Root: 50.

    Full postorder: 13, 30, 47, 40, 25, 70, 60, 77, 80, 75, 50.

    Step 4: Find the position of 60.

    Counting from 1: 13(1), 30(2), 47(3), 40(4), 25(5), 70(6), 60(7).

    The position is 7.

    Wrong path: Misplacing 70 as the left child of 80 (since 70 < 80), ignoring that 70 appeared before 80 in preorder and is > 60, so it must be in 60's subtree. This would shift the postorder sequence and the position of 60.

    Question 5 · Programming and Data Structures · 2026_Set1 MCQ
    Let be the set of all integers from 1 to 15. Consider any order of insertion of the elements of into a binary search tree that creates a complete binary tree.

    Which one of the following elements can NEVER be the third element that is inserted?
    1. A.

      4

    2. B.

      2

    3. C.

      10

    4. D.

      5

    Correct Answer:

    D

    Step-by-Step Solution

    Insight: This is a BST construction constraint question, recognizable because it asks about the validity of a specific insertion order to achieve a rigid structural outcome (a complete binary tree).

    Exam route: A complete BST of 1..15 has a fixed shape. The root must be the median (8). Its children must be the medians of the left (1..7 4) and right (9..15 12) subsets. The first three inserted elements must be the root and its two children (in some order: 8, then 4 and 12). The children of 4 are 2 and 6. The children of 12 are 10 and 14. Therefore, the 3rd element can only be 4, 12, 2, 6, 10, or 14. It cannot be 5.

    Learning route:

    Step 1: Understand the target structure. A complete binary tree with 15 nodes has 4 fully filled levels.

    Step 2: Identify the root. To be complete and a valid BST, the root must be the median of the entire set , which is 8. Thus, 8 must be the 1st element inserted.

    Step 3: Identify the second level. The left subtree contains and the right contains . For these subtrees to be complete, their roots must be their respective medians: 4 and 12.

    Step 4: Determine valid insertion orders. In BST insertion, a parent must be inserted before its children. Therefore, the first three elements inserted must be 8, followed by 4 and 12 in either order.

    Step 5: Analyze the "3rd element" constraint. If the sequence starts with 8, 4, the 3rd element can be 12 (the other level-1 node), or 2 or 6 (children of 4). If it starts with 8, 12, the 3rd element can be 4, or 10 or 14 (children of 12).

    Step 6: Evaluate the options. 4, 2, and 10 are all in the valid set of 3rd elements. 5 is a child of 6, meaning 6 must be inserted before 5. Thus, 5 cannot possibly be the 3rd element inserted.

    Wrong path: Assuming any number smaller than 8 can be inserted early. If 5 is inserted 3rd, it would become a child of 4 (since 5 > 4), but in a complete BST, the right child of 4 must be 6 to maintain the complete structure of the left subtree. This breaks the completeness constraint.

    Question 6 · Programming and Data Structures · 2025_Set2 NAT

    Suppose the values 10, −4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let be the resulting binary search tree. The number of edges in the path from the node containing 19 to the root node of is ___________. (Answer in integer)

    Correct Answer:

    4.00

    Step-by-Step Solution

    Insight: This is a BST path length question, recognizable because it provides a specific insertion sequence and asks for the number of edges between a target node and the root.

    Exam route: Construct the BST step-by-step using the given sequence. 10 is root. -4 is left of 10. 15 is right of 10. 30 is right of 15. 20 is left of 30. 5 is right of -4. 60 is right of 30. 19 is left of 20. The path from 19 to root is 19 20 30 15 10. Count the edges: 4.

    Learning route:

    Step 1: Initialize an empty BST.

    Step 2: Insert 10. It becomes the root.

    Step 3: Insert -4. , so it becomes the left child of 10.

    Step 4: Insert 15. , so it becomes the right child of 10.

    Step 5: Insert 30. (go right), (go right). It becomes the right child of 15.

    Step 6: Insert 20. (right), (right), (left). It becomes the left child of 30.

    Step 7: Insert 5. (left), (right). It becomes the right child of -4.

    Step 8: Insert 60. (all right). It becomes the right child of 30.

    Step 9: Insert 19. (right), (right), (left), (left). It becomes the left child of 20.

    Step 10: Trace the path from 19 to the root. The ancestors of 19 are 20, 30, 15, and 10.

    Step 11: Count the edges in this path. 19 to 20 (1), 20 to 30 (2), 30 to 15 (3), 15 to 10 (4). Total edges = 4.

    Wrong path: Counting the number of nodes in the path (5) instead of the number of edges (4), or incorrectly inserting 19 as a child of 15 or 30 directly, missing the intermediate node 20, leading to a path length of 3.

    Question 7 · Programming and Data Structures · 2025_Set2 MCQ
    Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in .

    Which ONE of the following is the number of nodes in that have exactly two children?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: This is a strict (full) binary tree property question, recognizable because it constrains every node to have exactly 0 or 2 children and asks for a node count formula.

    Exam route: Use the fundamental identity . Since it is a strict tree, . Total nodes . Substitute to get . Solve for to get .

    Learning route:

    Step 1: Define variables. Let be leaf nodes (0 children), be nodes with 1 child, and be nodes with 2 children.

    Step 2: Apply the given constraint. Every node has 0 or 2 children, so .

    Step 3: State the total node equation. .

    Step 4: Apply the universal binary tree edge property. Total edges = . Also, total edges = .

    Step 5: Equate and substitute. . Since , we have .

    Step 6: Solve for . .

    Verification: If (a root and two leaves), . This matches a root with two children.

    Wrong path: Assuming , which leads to (Option C), or assuming , leading to (Option A). These violate the fundamental edge-count derivation.

    Question 8 · Programming and Data Structures · 2025_Set1 MSQ

    Which of the following statement(s) is/are <b>TRUE</b> for any binary search tree (BST) having distinct integers?

    1. A.

      The maximum length of a path from the root node to any other node is .

    2. B.

      An inorder traversal will always produce a sorted sequence of elements.

    3. C.

      Finding an element takes time in the worst case.

    4. D.

      Every BST is also a Min-Heap.

    Correct Answer:

    ["A","B"]

    Step-by-Step Solution

    Insight: A BST's inorder traversal is always sorted, and its maximum possible depth is (achieved by a completely skewed tree).

    Exam route: Evaluate each option. A is true because a tree with nodes has at most edges in any path. B is true by the definition of BST. C is false because worst-case search is for a skewed tree. D is false because BST ordering (left < parent < right) does not imply heap ordering (parent children).

    Learning route:

    1. Option A: A path in a tree with nodes can have at most nodes, which means edges. A right-skewed BST achieves exactly this maximum length. Thus, the maximum length is bounded by and can be .
    2. Option B: The BST property (left subtree < node < right subtree) guarantees that an inorder traversal (Left, Node, Right) visits elements in strictly ascending order.
    3. Option C: Search time is , where is the height. In the worst case (skewed tree), , making the time complexity , not .
    4. Option D: A Min-Heap requires every parent to be its children. A BST only requires left child < parent < right child. For example, a BST with root 10, left child 5, and right child 15 violates the Min-Heap property because 10 is not 5.

    Verification: For , elements inserted as gives a right-skewed tree. Path length from root (1) to leaf (3) is 2 edges (). Inorder is (sorted). Search for 3 takes 3 steps (). Root 1 is not left child (none), but if we had root 2, left 1, right 3, 2 is not 1, so not a min-heap.

    Question 9 · Programming and Data Structures · 2024_Set2 MCQ
    You are given a set of distinct integers. A binary search tree is created by inserting all elements of one by one, starting with an empty tree. The tree follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into , and you do not have access to .

    Which one of the following statements is TRUE?
    1. A.

      Inorder traversal of can be determined from

    2. B.

      Root node of can be determined from

    3. C.

      Preorder traversal of can be determined from

    4. D.

      Postorder traversal of can be determined from

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: Inorder traversal of any BST with distinct keys always yields the keys in sorted ascending order, regardless of the insertion sequence.

    Exam route: The set contains all distinct elements. Sorting gives the unique inorder traversal. Root, preorder, and postorder depend on the unknown insertion order, so they cannot be determined. Thus, only inorder is determinable.

    Learning route:

    1. A BST enforces the invariant: for any node, all left descendants are smaller, and all right descendants are larger.
    2. Inorder traversal visits Left, then Node, then Right.
    3. By induction, this recursively guarantees that the output sequence is strictly sorted.
    4. Since we are given the set , we can simply sort its elements to obtain this sequence.
    5. The root is the first element inserted, which is unknown. Preorder and postorder depend on the tree structure, which varies with insertion order.

    Verification: If , sorted is . Whether inserted as or , the inorder traversal is always .

    Question 10 · Programming and Data Structures · 2023 MCQ
    Consider the C function foo and the binary tree shown.

    typedef struct node {
       int val;
       struct node *left, *right;
    } node;

    int foo(node *p) {
       int retval;
       if (p == NULL)
          return 0;
       else {
          retval = p->val + foo(p->left) + foo(p->right);
          printf("%d ", retval);
          return retval;
       }
    }

    105113813

    When foo is called with a pointer to the root node of the given binary tree, what will it print?
    1. A.

      3 8 5 13 11 10

    2. B.

      3 5 8 10 11 13

    3. C.

      3 8 16 13 24 50

    4. D.

      3 16 8 50 24 13

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: This is a recursive tree processing question, recognizable because the function makes recursive calls on left and right children before executing a print statement, indicating a post-order traversal with an accumulation operation.

    Exam route: The function computes the sum of the subtree rooted at each node and prints it. Since the print happens after the recursive calls, it's a post-order traversal. Trace the tree bottom-up: leaves print their own values (3, 8, 13). Their parents print the sum of their subtrees (5+3+8=16, 11+0+13=24). The root prints the total sum (10+16+24=50). Output: 3, 8, 16, 13, 24, 50.

    Learning route:

    Step 1: Analyze the function foo. Base case: returns 0 for NULL. Recursive step: retval = p->val + foo(p->left) + foo(p->right). Action: printf("%d ", retval).

    Step 2: Identify the traversal order. The action (print) occurs after both recursive calls. This is the definition of post-order traversal (Left, Right, Root).

    Step 3: Identify the computed value. retval is the sum of the current node's value and the return values of its left and right subtrees. Thus, it prints the sum of each subtree.

    Step 4: Trace the execution on the given tree.

    • foo(3): returns 3, prints 3.
    • foo(8): returns 8, prints 8.
    • foo(5): retval = 5 + 3 + 8 = 16. Prints 16, returns 16.
    • foo(NULL) (left of 11): returns 0.
    • foo(13): returns 13, prints 13.
    • foo(11): retval = 11 + 0 + 13 = 24. Prints 24, returns 24.
    • foo(10): retval = 10 + 16 + 24 = 50. Prints 50, returns 50.

    Step 5: Collect the printed sequence: 3, 8, 16, 13, 24, 50.

    Wrong path: Tracing the traversal order correctly (post-order) but forgetting that the function prints the accumulated sum (retval), not the original p->val. This leads to selecting the option that lists the raw node values in post-order (3, 8, 5, 13, 11, 10), which is Option A.

    More previous year questions (pyqs) in this unit