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 #buildtree which you'll write next.
Write a #buildtree method that takes an array of data eg and turns it into a balanced binary tree full of Node objects appropriately placed dont forget to sort and remove duplicates! The #buildtree method should return the level root node.
Write an #insert and #delete method which accepts a value to insertdelete
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 #buildtree which you'll write next.
Write a #buildtree method that takes an array of data eg and turns it into a balanced binary tree full of Node objects appropriately placed dont forget to sort and remove duplicates! The #buildtree method should return the level root node.
Write an #insert and #delete method which accepts a value to insertdelete
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
