Professional Documents
Culture Documents
Important Note:
Part #1. Given an array of integers, design an algorithm and implement in C++
to construct a balanced binary search tree (BST). In a balanced BST, the heights of
all leaf nodes can differ at most by 1. As an example, given an input array (3, 2, 1,
4, 6, 5), here are examples of balanced BST versus unbalanced BST:
In the above example, the left BST is balanced because the difference of heights
for all the leaf nodes is less than 1. The right BST is unbalanced because the
difference of height for some leaf nodes ( “3” and “1”) is 2, which is larger than 1.
Note that the integers in the given array may not be sorted.
You should utilize the data structure and methods defined in the codes BST.h and
BST.cpp, and implement this part in a “driver” program.
Part #2. Conduct an in-order traversal of the BST you constructed in Part #1 and
print out the nodes in that order. You may re-use the inOrder traversal method you
developed in the programming assignment.
Files to be submitted:
Program files: all the codes that are needed to compile and run successfully.
Submission instruction: Zip all the above files into a single file as
‘Final_Submission_yourname’ and submit to iLearn