Question: **Please use C++ for all Questions** 1. Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right,

**Please use C++ for all Questions**

1. Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

For example: Given binary tree [3, 9, 20, NULL, NULL, 15, 7]

return its level order traversal.

2. Given a binary tree, return the inorder traversal of its nodes values using stack. Given binary tree [1,null,2,3], return [1,3,2].

3. Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3, which represents the number 123. Find the total sum of all root-to-leaf numbers

**Below are some helper functions to assit with the questions** #include  using namespace std; struct TreeNode { int value; TreeNode* left; TreeNode* right; TreeNode(int data) { value = data; left = right = NULL; } };
// calculate the height of a binary search tree int maxDepth(TreeNode* root) { if (root == NULL) // base case: empty tree return 0; return 1 + max(maxDepth(root->left), maxDepth(root->right)); } TreeNode* add(TreeNode* root, int data) { if (root == NULL) { TreeNode* res = new TreeNode(data); return res; } if (data > root->value) { root->right = add(root->right, data); } else { root->left = add(root->left, data); } return root;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!