Back to Portfolio

Binary Search Tree Program

UML diagram of the program, the GUI in action, and a visual representation of the binary search tree

Binary Search Tree Program main image

Letters of the alphabet added in random order, printed in sorted order, and removed

Binary Search Tree Program screenshot 1

Full UML class diagram, implementing Java's Set interface

Binary Search Tree Program screenshot 2

Each Node stores a String and has left/right child references

Binary Search Tree Program screenshot 3

Methods that perform an in-order traversal of the tree to output a sorted list

Binary Search Tree Program screenshot 4

Letters added in random order, in-order traversal animation of what the recursion is doing

Binary Search Tree Program screenshot 5

Size methods use recursion to calculate how many elements in the tree

Binary Search Tree Program screenshot 6

contains(): used to not allow duplicates (definition of a Set)

Binary Search Tree Program screenshot 7

How the recursive algorithm works for contains()

Binary Search Tree Program screenshot 8

Recursive insertion logic for adding an element

Binary Search Tree Program screenshot 9

Visual animation of letters being added in random order - tree grows dynamically

Binary Search Tree Program screenshot 10

remove() covers all 3 removal cases: leaf, node with 1 child, and node with 2 children (predecessor replacement)

Binary Search Tree Program screenshot 11

Showing live deletion of the aforementioned 3 different removal cases - including replacing the root

Binary Search Tree Program screenshot 12

Shows automatic saving and loading of the BST object when closing/opening the program

Binary Search Tree Program screenshot 13

A fully custom Java-based implementation of a Binary Search Tree that fulfills the Java Set interface while also providing a live UI and BST visualizer. This project was designed to support a larger game project, where maintaining and organizing large collections of enum values required an efficient and structured backend solution. The BSTSet program ensures all string-based elements remain sorted, unique, and accessible in logarithmic time.

The visual interface allows users to insert, remove, and check elements with real-time feedback, offering an educational view into how binary trees operate. It supports in-order traversal for sorted output, full recursive logic for add, remove, contains, and size, and shows the structural changes dynamically through animated tree drawing. The UI also supports automatic save/load functionality via .dat file serialization, making it possible to resume previous sessions instantly.

Key features include: - Full compliance with the Java Set interface - Recursive methods for all tree operations, preserving balance and uniqueness - Real-time visualizer that animates tree growth, removal, and traversal - A graphical user interface for input/output - Object serialization using Java’s I/O libraries to persist the tree state between runs

This tool was invaluable for backend enum organization in a custom RPG game and serves as both a practical utility and a learning resource for data structures and recursion.

June 2023

Technologies Used:

Java Core Libraries:

Implements Set and Serializable interfaces to manage collections and persist data.

Binary Search Tree (BST):

Supports recursive add(), remove(), contains(), size(), and in-order traversal to maintain order and uniqueness.

Java Swing GUI:

Built with JFrame, JPanel, JButton, JTextField, and JOptionPane for real-time interaction and visualization.

Event-Driven Programming:

Uses ActionListener for user input and WindowAdapter to save data on exit.

File I/O & Serialization:

Saves and loads tree state with ObjectOutputStream and ObjectInputStream.

String Handling:

Case-insensitive logic with utility-based proper casing for display.