Skip to content

ShouNLAK/BST-TreeSet-Comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

BST vs. TreeSet Benchmark in Java

Developed by ShouNLAK


πŸ” Overview

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.

⚠️ This project is a student endeavor; results may not reflect industrial-grade precision.


πŸ“‹ Table of Contents


πŸ“Š Benchmark Details

βœ”οΈ 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.


πŸš€ How to Run

πŸ’» 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

▢️ Step 3: Run the Application

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 & A

πŸ”Έ 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).

Worst-Case Scenario: BST vs. TreeSet

TreeSet (Self-Balancing) BST (Unbalanced)
TreeSet BST
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!

About

BST vs. TreeSet - Standard Java

Topics

Resources

Stars

Watchers

Forks

Languages