Developed by ShouNLAK
This project benchmarks the performance of a custom Binary Search Tree (BST) against Java's built-in TreeSet, focusing on key operations under different conditions:
π Regular Case: Balanced operations with O(log n) performance.
π Worst Case: BST degrades to O(n) when unbalanced, while TreeSet remains O(log n) consistently.
βοΈ User-Defined Test Size β Specify the number of elements to process.
βοΈ Warm-Up Phase β Minimizes JIT overhead for accurate timing.
βοΈ Timed Operations:
- β³ Insertion β Adding elements
- π Finding β Searching for elements
- β Deletion β Removing elements
Each operation is executed 30 times, with an average runtime summary displayed for clarity.
βοΈ Detailed Summary β Results formatted with tables, bullet points & highlights.
βοΈ User-Friendly UI β Well-structured outputs for easy readability.
π» Step 1: Clone the Repository
git clone https://github.com/ShouNLAK/BSTvsTreeSet.git
cd BSTvsTreeSetπ¨ Step 2: Build the Project
- Using Gradle:
./gradlew build
- Using Maven:
mvn clean install
java -jar build/libs/BSTvsTreeSet.jarβοΈ Step 4: Follow On-Screen Prompts
- Enter the test size
- Benchmark runs for Insertion, Finding, & Deletion
- Results summary displayed
πΈ Q: Why compare BST vs. TreeSet?
A: BST is a fundamental data structure in computer science, but Javaβs TreeSet offers built-in balancing. This benchmark helps analyze their performance in real-world scenarios.
πΈ Q: What is the worst-case scenario for BST?
A: If data is inserted in an almost sorted order, the BST becomes a skewed tree (similar to a linked list), degrading performance to O(n) instead of O(log n).
| TreeSet (Self-Balancing) | BST (Unbalanced) |
|---|---|
![]() |
![]() |
| Maintains O(log n) even with sorted insertions | Degrades to O(n) when inserted in order |
πΈ Q: Why does TreeSet maintain better performance?
A: TreeSet uses a Red-Black Tree, a self-balancing binary search tree that ensures O(log n) complexity for insertion, search, and deletion operations.
πΈ Q: Does the benchmark consider memory usage?
A: This version primarily focuses on execution speed. Future improvements could integrate memory profiling.
πΈ Q: Can I use this for production-level analysis?
A: Since this is a student project, results might not be precise enough for high-stakes applications. However, it serves as a solid learning tool.
β‘ Use this benchmark as a learning tool for further optimization.
Let me know if youβd like additional formatting enhancements!


