Question: PLEASE CODE IN C++ ------------------------------- As you know, when you insert values to a tree, the values greater will go to the right side and
PLEASE CODE IN C++
-------------------------------


As you know, when you insert values to a tree, the values greater will go to the right side and the values smaller go to the left side. The tree will be extremely skewed if you insert values in the order from the smallest to the largest or from the largest to the smallest. For example, if you insert 31 values 1, 2, 3,.. 31 in the listed order, the tree will look like 3 The tree becomes a list (with the depth of 30) and it is not optimized for the search Your task is to write a member function to optimize the tree to make the depth of the tree to be (Log.(n+1)-1 (n is the number of nodes). For example, the above tree will be optimized to: 12 20 10 26 15 23 25 27 31 You can see the depth of the tree becomes 4. The tree of this structure is the best for the search. Please keep it in mind: your optimizing algorithm should not be hardcoded and should be able to apply to all binary trees regardless the content of the trees. Instruction and Test: Use your assignment 8 as the base. Develop an algorithm and implement it in a public member function called Optimize) with void return. To test your code, insert following code into your main function: Tree
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
