Question
Consider the following C++-like pseudo-code for a binary
tree traversal:   ```cpp   struct Node {     int data;     Node left;     Node right;   };   void trickyTraversal(Node root) {     if (root == nullptr) {       return;     }     if (root->left != nullptr) {       trickyTraversal(root->left);     }     std::cout data right != nullptr) {       trickyTraversal(root->right);     }   }   ```   Given the following binary tree:   ```      10      / \     5  15     / \  /    2  7 12   ```   What will be the output of `trickyTraversal(root)` where `root` points to the node with data `10`?ÂSolution
The `trickyTraversal` function is an Inorder Traversal.       It first recursively visits the left child.       Then it prints the current node's data.       Then it recursively visits the right child.     This is the definition of an Inorder Traversal.     For the given tree:     ```        10        / \       5  15       / \  /      2  7 12     ```     Inorder traversal: Left -> Root -> Right     1. `trickyTraversal(10)`       1.1. `trickyTraversal(5)`         1.1.1. `trickyTraversal(2)`           1.1.1.1. `trickyTraversal(nullptr)` -> return           1.1.1.2. Print `2`           1.1.1.3. `trickyTraversal(nullptr)` -> return         1.1.2. Print `5`         1.1.3. `trickyTraversal(7)`           1.1.3.1. `trickyTraversal(nullptr)` -> return           1.1.3.2. Print `7`           1.1.3.3. `trickyTraversal(nullptr)` -> return       1.2. Print `10`       1.3. `trickyTraversal(15)`         1.3.1. `trickyTraversal(12)`           1.3.1.1. `trickyTraversal(nullptr)` -> return           1.3.1.2. Print `12`           1.3.1.3. `trickyTraversal(nullptr)` -> return         1.3.2. Print `15`         1.3.3. `trickyTraversal(nullptr)` -> return     Output: `2 5 7 10 12 15`
What is the significance of the recently discovered fossil, Megamonodontium mccluskyi, in Australia?
What is the significance of the recently launched warship 'Triput' constructed by Goa Shipyard Limited (GSL) for the Indian Navy?
What is India's ranking in the 2024 Environmental Performance Index?
Which of the following indices will include Indian Government Securities (G-Secs) as part of global market indices, and what is the significance of this...
What is the deadline for achieving "Housing for All" as per the extended target under Pradhan Mantri Awas Yojana?
What position has Ajay Singh assumed in the International Boxing Association (IBA)?
Direct tax collections in India increased by what percentage over the past 10 years?
With reference to ‘Old Pension Scheme’, consider the following statements:
I. Employees get a pension under a pre-determined formula which is...
World Breastfeeding week 2022 was celebrated from ____?
What is the initial financial commitment of Karnataka government to the B-SMILE infrastructure initiative?