Skip to content

Conversation

SChandrasekhar96
Copy link

@SChandrasekhar96 SChandrasekhar96 commented Jul 1, 2025

This PR adds an implementation of a Binary Search Tree (BST) in Java under the tree package.

Features:

  • Insertion of nodes
  • Inorder Traversal
  • Preorder Traversal
  • Postorder Traversal

Closes #6334

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2025

Codecov Report

Attention: Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.

Project coverage is 74.18%. Comparing base (712ada5) to head (59ac14e).

Files with missing lines Patch % Lines
.../java/com/thealgorithms/tree/BinarySearchTree.java 0.00% 37 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6334      +/-   ##
============================================
- Coverage     74.33%   74.18%   -0.15%     
  Complexity     5392     5392              
============================================
  Files           679      680       +1     
  Lines         18820    18857      +37     
  Branches       3646     3648       +2     
============================================
  Hits          13990    13990              
- Misses         4274     4311      +37     
  Partials        556      556              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vil02
Copy link
Member

vil02 commented Jul 1, 2025

I have an impression that this is already implemented in BinaryTree.java.

@SChandrasekhar96
Copy link
Author

I have an impression that this is already implemented in BinaryTree.java.

Hi @vil02, thank you for pointing that out!

I checked BinaryTree.java, and it appears to implement a general binary tree without enforcing BST properties during insertion (i.e., no ordering based on key values). This PR provides a specific Binary Search Tree implementation where nodes are inserted based on the BST rule: left < root < right.

If you'd still prefer this be merged under BinaryTree.java or as an enhancement to it, I’m happy to modify the structure accordingly.

@vil02
Copy link
Member

vil02 commented Jul 2, 2025

@SChandrasekhar96: could you elaborate on that? Looking at the put I think the linked implementation maintains the BST order.

@SChandrasekhar96 SChandrasekhar96 deleted the binary-search-tree branch July 17, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants