Question: You'll build a simple binary search tree in this activity. Build a Node class. It should have attributes for the data it stores as well

You'll build a simple binary search tree in this activity.
Build a Node class. It should have attributes for the data it stores as well as its left and right children. As a bonus, try including the Comparable module and make nodes compare using their data attribute.
Build a Tree class that accepts an array when initialized. The Tree class should have a root attribute that uses the return value of #build_tree which you'll write next.
Write a #build_tree method that takes an array of data (e.g.[1,7,4,23,8,9,4,3,5,7,9,67,6345,324]) and turns it into a balanced binary tree full of Node objects appropriately placed (don't forget to sort and remove duplicates!). The #build_tree method should return the level-1 root node.
Write an #insert and #delete method which accepts a value to insert/delete.
Build a Node class. It should have attributes for the data it stores as well as its left and right children. As a bonus, try including the Comparable module and make nodes compare using their data attribute.
Build a Tree class that accepts an array when initialized. The Tree class should have a root attribute that uses the return value of #build_tree which you'll write next.
Write a #build_tree method that takes an array of data (e.g.[1,7,4,23,8,9,4,3,5,7,9,67,6345,324]) and turns it into a balanced binary tree full of Node objects appropriately placed (don't forget to sort and remove duplicates!). The #build_tree method should return the level-1 root node.
Write an #insert and #delete method which accepts a value to insert/delete.

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!