Question: In Python, write a driver script that does the following: Create a binary search tree from an array of random numbers ( ` Array .

In Python, write a driver script that does the following:
Create a binary search tree from an array of random numbers (`Array.new(15){ rand(1..100)}`)
Confirm that the tree is balanced by calling `#balanced?`
Print out all elements in level, pre, post, and in order
Try to unbalance the tree by adding several numbers 100
Confirm that the tree is unbalanced by calling `#balanced?`
Balance the tree by calling `#rebalance!`
Confirm that the tree is balanced by calling `#balanced?`
Print out all elements in level, pre, post, and in order

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 Programming Questions!