πŸ”– Background Information

A binary tree data structure consists of a set of nodes, each carrying a piece of data. Every node in the tree can point to up to two children, canonically called β€œleft” and β€œright”. This short article (Programiz, n.d.) from Programiz gives a nice overview of the binary tree structure.

🎯 Problem Statement

Write a binary tree data structure that stores Squirrel objects.

βœ… Acceptance Criteria

  • The nodes of the binary tree data structure should be objects.
  • I should be able to create a node and attach it to an existing node in the tree. Moreover, I should be able to specify whether I want to connect the new node as the β€œleft” or β€œright” child.
  • I should be able to traverse the tree, starting from the root and moving to the leaves. Moreover, I should be able to move to the two child nodes of a given node using the left and right methods.
  • You do not have to implement a generic tree structure. You can instead have each Node object store a Squirrel directly. There is an extra credit opportunity to make the nodes generic.

πŸ“‹ Dev Notes

  • You cannot use any built-in classes from the standard library that implement trees. You need to implement this data structure from scratch.
  • You do not have to implement the Squirrel object from scratch. I have provided it here:

πŸ–₯️ Example Output

You could create a driver program that tests the binary tree data structure. It might look something like this:

πŸ“ Thought Provoking Questions

  1. How is a binary tree with one long branch related to a linked list?
  2. Why are we so interested in keeping binary trees balanced (i.e. approximately equal numbers of nodes on the left and right)?

πŸ’Ό Optional Extra Credit

(1/2 Point) Generic Node

Update your Node class to allow the user to specify what type of object will be stored in the tree. You can use a template to specify the type of object. The behavior of your binary tree should not change otherwise.

πŸ“˜ Works Cited

Programiz. (n.d.). Binary Tree. In Programiz. Retrieved April 27, 2024, from https://www.programiz.com/dsa/binary-tree