Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

What is the real interest rate?

Answered: 1 week ago