solution

Write down recursive tree algorithms for the following problems. In each problem, the input is a pointer to the root of a binary tree. The definition of the tree node is shown below. Your algorithm should support the special case of an empty tree which is denoted by a NULL pointer to its root. Analyze the worst-case running time of each algorithm using the Big-Oh notation. struct tree_node { int value; tree_node *left, *right; }; 1. (2 points) Compute the height of the tree. Assume the height of an empty tree is -1. 1 2. (2 points) Compute the sum of all values in the tree nodes. The sum of an empty tree is 0. 3. (2 points) Search for a given integer value x and return true if the tree has a node with the given value; false otherwise. 1. (1 points) Compute the number of nodes at each level of the tree. The return value is a list of integers where the entry at the position i c [0,h] (h is the height of the tree) indicates the number of nodes with depth i. For an empty tree, an empty list is returned. For example, for the tree used in Question 1, the return value is [1,2,3,3).

Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp