Simple binary tree activity: Build a Node class. It should have attributes for the data it stores
Fantastic news! We've Found the answer you've been seeking!
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. 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.
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date: