{"id":20271954,"url":"https://github.com/hoangsonww/binary-search-tree-dsa","last_synced_at":"2025-10-14T01:10:37.733Z","repository":{"id":221903784,"uuid":"686785910","full_name":"hoangsonww/Binary-Search-Tree-DSA","owner":"hoangsonww","description":"🌳 This repository is dedicated to the Binary Search Tree (BST) data structure, featuring a comprehensive demo of all its functionalities including insertion, deletion, search, and traversal operations. It serves as an educational resource for understanding BSTs in depth, offering code examples and explanations suitable for students and developers.","archived":false,"fork":false,"pushed_at":"2025-04-09T18:04:21.000Z","size":24,"stargazers_count":21,"open_issues_count":0,"forks_count":12,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-11T04:34:17.077Z","etag":null,"topics":["algorithms","binary-search","binary-search-algorithm","binary-search-tree","binary-search-tree-operations","binary-search-tree-traversal","binary-tree","binary-tree-array","binary-tree-linked-list","bst","bst-tree","data-structures","java","java-8"],"latest_commit_sha":null,"homepage":"https://hoangsonww.github.io/Binary-Search-Tree-DSA/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hoangsonww.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-03T23:38:28.000Z","updated_at":"2025-03-23T04:49:52.000Z","dependencies_parsed_at":"2024-02-10T23:30:34.543Z","dependency_job_id":"31f716d2-3b2a-4dd2-8547-18717131da64","html_url":"https://github.com/hoangsonww/Binary-Search-Tree-DSA","commit_stats":null,"previous_names":["hoangsonww/binary-search-tree-dsa"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hoangsonww/Binary-Search-Tree-DSA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FBinary-Search-Tree-DSA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FBinary-Search-Tree-DSA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FBinary-Search-Tree-DSA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FBinary-Search-Tree-DSA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoangsonww","download_url":"https://codeload.github.com/hoangsonww/Binary-Search-Tree-DSA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FBinary-Search-Tree-DSA/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017456,"owners_count":26086081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","binary-search","binary-search-algorithm","binary-search-tree","binary-search-tree-operations","binary-search-tree-traversal","binary-tree","binary-tree-array","binary-tree-linked-list","bst","bst-tree","data-structures","java","java-8"],"created_at":"2024-11-14T12:40:26.469Z","updated_at":"2025-10-14T01:10:37.699Z","avatar_url":"https://github.com/hoangsonww.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binary Search Tree - DSA Project\n\n## Overview\nThis Java project implements a Binary Search Tree (BST) with fundamental operations such as insertion, deletion, and traversal. Designed with efficiency and simplicity in mind, this class provides an intuitive way to manage and manipulate a collection of integers in a hierarchical structure.\n\n## Features\n- **Dynamic Tree Construction**: Create a BST either empty, with a single root node, or by parsing an array of integers.\n- **Insertion**: Add new elements to the tree while maintaining the BST properties.\n- **Deletion**: Remove elements from the tree, adjusting the structure as necessary to preserve BST properties.\n- **Search**: Check whether a specific value exists within the tree.\n- **Traversal**: Inorder, preorder, and postorder traversal methods to explore the tree's contents.\n- **K-th Smallest Element**: Retrieve the k-th smallest element from the tree, demonstrating an application of inorder traversal.\n- **Create Tree from Array**: Build a new BST from an array of integers, replacing any existing tree.\n\n## Prerequisites\n- Java Development Kit (JDK) 11 or later.\n- A Java IDE (e.g. IntelliJ IDEA or Eclipse) is highly recommended.\n\n## Setup and Compilation\n1. Ensure Java is installed on your system. You can verify this by running `java -version` in your command line or terminal.\n2. Clone or download this repository to your local machine.\n3. Navigate to the directory containing the `BinarySearchTree.java` file.\n4. Compile the class using the Java compiler:\n   ```bash\n   javac BinarySearchTree.java\n   ```\n\n## Usage\n### Creating a BST\nInstantiate a BST object in your Java program. You can create a tree in three ways:\n- Empty tree: `BinarySearchTree bst = new BinarySearchTree();`\n- Tree with an integer root: `BinarySearchTree bst = new BinarySearchTree(10);`\n- Tree with a Node as root: `BinarySearchTree bst = new BinarySearchTree(new Node(10));`\n\n### Inserting Elements\nAdd elements to your BST:\n```java\nbst.insert(5);\nbst.insert(15);\n```\n\n### Deleting Elements\nRemove elements by value:\n```java\nbst.delete(5);\n```\n\n### Searching for Elements\nCheck if an element exists in the tree:\n```java\nboolean found = bst.search(15);\n```\n\n### Traversing the Tree\nPerform different tree traversals:\n```java\nbst.inorderRec();\nbst.preorderRec();\nbst.postorderRec();\n```\n\n### Finding the K-th Smallest Element\nRetrieve the k-th smallest element from the BST:\n```java\nNode kthSmallest = bst.kthSmallest(3);\nif (kthSmallest != null) {\n    System.out.println(\"K-th Smallest: \" + kthSmallest.key);\n}\n```\n\n### Creating a Tree from an Array\nOverwrite the current tree with a new tree constructed from an array of integers:\n```java\nint[] values = {3, 1, 4, 2};\nbst.createTree(values);\n```\n\n### Main File\nThere is also a Main.java file, which comprehensively tests all the functions and methods of the BST class. Feel free to run it as follows:\n```bash\njava Main\n```\n\n## Contributing\nContributions to improve the Binary Search Tree implementation or extend its functionality are welcome. Please fork the repository, make your changes, and submit a pull request with a clear description of your modifications or additions.\n\n---\n\nCreated with ❤️ by [Son Nguyen](https://github.com/hoangsonww) in 2023.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoangsonww%2Fbinary-search-tree-dsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoangsonww%2Fbinary-search-tree-dsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoangsonww%2Fbinary-search-tree-dsa/lists"}