Ethan Song
Gentry-Kolen
COMSC-210
12 April 2020
Binary Search Tree Lab Report
Assignment Description: For this lab, you will create an implementation of a binary search tree
(BST), using preorder traversal on the following set: { 8, 4, 2, 5, 12, 29 }.
Discussion:
• Solution Description: This program implements a BinarySearchTree (BST) class in C++,
consisting of a Node structure with pointers to other Nodes. This structure-pointer
relationship comprises of the entire tree. Functions include recursive add, remove,
contains, and preorder traversal/print functions, along with a getSize() function.
• Chart:
BST
+ Node: struct
• + data: int
• + left: Node
• + right: Node
• + Node(int)
+ root: Node
+ size: int
+ BST()
+ add(int): void
+ add(struct Node*, int): void
+ remove(int): struct Node*
+ remove(struct Node*, int): struct Node*
+ printPreOrder(struct Node*): void
+ contains(int): bool
+ contains(struct Node*, int): bool
+ getSize(): int
• Major Implementation Issues: The most difficult parts of the program to implement
included the recursive add and remove functions, since it was tricky to both handle
where the pointers are pointed while analyzing the recursive nature of each function.
• Screen Shot:
Known Bugs/Errors:
• The size of the tree is determined by a global size tracking variable which is incremented
and decremented whenever the non-recursive add and remove functions are called,
respectively. Therefore, an empty tree with size 0 can have a negative size value if the
remove functions is called.
Lessons Learned:
• What Went Well: The implementation of the tree went smoothly, and the result of this
lab came a fully functioning BST with proper add, remove, search, and print functions.
• What would you do differently next time: Next Time, I would try to plan out the
implementation structure more, for example using pen and paper, rather than jumping
to code too quickly.