Question: Simple binary tree activity: Build a Node class. It should have attributes for the data it stores as well as its left and right children.
Simple binary tree 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.
- Have 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
3.50 Rating (157 Votes )
There are 3 Steps involved in it
class Node def initself data selfdata data selfleft None selfright None def ltself other return self... View full answer
Get step-by-step solutions from verified subject matter experts
