Ordered Binary Search Tree (BST) Engine
Self-contained binary search tree data structure supporting logarithmic insertions, key lookups, in-order successor deletions, and recursive traversals.
Live Binary Search Tree (BST) Visualizer
Renders recursive node insertions and orders matching your Java BST.java
Project Overview & Architecture
Engineered from scratch in Java without utilizing standard library collections. The implementation defines a recursive Node structure that maintains binary search invariants, supporting logarithmic time complexity for insertions and lookups, alongside full in-order, pre-order, and post-order traversal routines.
Key Implementation Highlights
- ✓Recursive traversal methods: In-Order (sorted output), Pre-Order, and Post-Order.
- ✓Complete node deletion handling all three cases: leaf nodes, single-child nodes, and two-child nodes.
- ✓Algorithmic verification testing edge-case key lookups and tree height measurements.
Implementation Source Code
1 File12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970class Node {
int data;
Node left, right;
public Node(int value) {
data = value;
left = right = null;
}
}
public class BST {
private Node root;
public BST() {
root = null;
}
public void insert(int value) {
root = insertHelper(root, value);
}
private Node insertHelper(Node node, int value) {
if (node == null) {
return new Node(value);
}
if (value < node.data) {
node.left = insertHelper(node.left, value);
} else {
node.right = insertHelper(node.right, value);
}
return node;
}
// Traversal methods
public void inorderTraversal(Node node) {
if (node != null) {
inorderTraversal(node.left);
System.out.print(node.data + " ");
inorderTraversal(node.right);
}
}
public void preorderTraversal(Node node) {
if (node != null) {
System.out.print(node.data + " ");
preorderTraversal(node.left);
preorderTraversal(node.right);
}
}
public void postorderTraversal(Node node) {
if (node != null) {
postorderTraversal(node.left);
postorderTraversal(node.right);
System.out.print(node.data + " ");
}
}
public void levelorderTraversal() {
if (root == null) return;
java.util.Queue<Node> queue = new java.util.LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
Node current = queue.poll();
System.out.print(current.data + " ");
if (current.left != null) queue.add(current.left);
if (current.right != null) queue.add(current.right);
}
}
}Technologies & Tools
Academic Classification
More in Data Structures, Algorithms & Small Lab Projects
View all in categoryMulti-Language Graph Algorithms Suite (C++, Java, Python)
Comprehensive tri-lingual implementation of fundamental graph structures, benchmarking traversal, topological sorting, and shortest paths in C++, Java, and Python.
Emergency Room Triage Priority Queue Simulator
Hospital emergency room triage intake simulation that dynamically orders and dispatches patients by clinical acuity scores rather than arrival order.
Shunting-Yard Infix to Postfix Converter & Stack Calculator
Mathematical expression parsing engine that converts standard human-readable arithmetic into Reverse Polish Notation (RPN) and computes results via operand stacks.