{"id":21311633,"url":"https://github.com/sreddy-96/top-binary-search-tree","last_synced_at":"2025-03-15T20:42:57.618Z","repository":{"id":248978498,"uuid":"829900314","full_name":"SReddy-96/TOP-binary-search-tree","owner":"SReddy-96","description":"The Odin Project - Binary Search Trees project","archived":false,"fork":false,"pushed_at":"2024-07-18T06:12:11.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T09:48:49.634Z","etag":null,"topics":["algorithms","binary-search-tree","data-structures","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/SReddy-96.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}},"created_at":"2024-07-17T08:06:06.000Z","updated_at":"2024-07-18T06:12:14.000Z","dependencies_parsed_at":"2024-07-18T08:05:06.368Z","dependency_job_id":"0ac9cbb0-25fd-4605-a23b-aec22c83a730","html_url":"https://github.com/SReddy-96/TOP-binary-search-tree","commit_stats":null,"previous_names":["sreddy-96/top-binary-search-tree"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SReddy-96%2FTOP-binary-search-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SReddy-96%2FTOP-binary-search-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SReddy-96%2FTOP-binary-search-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SReddy-96%2FTOP-binary-search-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SReddy-96","download_url":"https://codeload.github.com/SReddy-96/TOP-binary-search-tree/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790945,"owners_count":20348378,"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","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-tree","data-structures","javascript"],"created_at":"2024-11-21T17:19:08.417Z","updated_at":"2025-03-15T20:42:57.593Z","avatar_url":"https://github.com/SReddy-96.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binary Search Tree Implementation - The Odin Project\n\n## Project Overview\n\nThis project involves creating a Balanced Binary Search Tree (BST) that takes an array, removes duplicates, sorts it, and constructs an efficient tree structure. The goal is to implement a BST that offers quick lookup, insertion, and deletion operations.\n\n## Key Features\n\n- Custom Tree class that converts array elements into nodes with left and right children for efficient navigation\n- Handling of data duplications during tree creation and insertion\n- Utilization of `module.exports` for easy integration into other projects\n- Methods to check if the tree `isBalanced` and to `reBalance` when necessary\n\n## Core Functionalities\n\n- `insert(value)`: Adds a new node to the tree, avoiding duplicates\n- `deleteItem(value)`: Removes a node and redistributes its children if necessary\n- `find(value)`: Locates and returns the node with the given value\n- Breadth-first traversal:\n  - `levelOrder(callback)`: Traverses the tree level by level, optionally applying a callback function\n- Depth-first traversals (all accept an optional callback):\n  - `inOrder()`: Returns nodes in left =\u003e data =\u003e right order\n  - `preOrder()`: Returns nodes in root =\u003e left =\u003e right order\n  - `postOrder()`: Returns nodes in left =\u003e right =\u003e root order\n- `height(node)`: Calculates the height of a given node (longest path to a leaf)\n- `depth(node)`: Determines the depth of a given node (distance from the root)\n- `isBalanced()`: Checks if the tree is balanced\n- `reBalance()`: Restructures an unbalanced tree to achieve balance\n\n## Challenges and Solutions\n\n1. **Creating an array of unique values**: Solved using `[...new Set()]` to efficiently remove duplicates\n2. **Exporting classes**: Implemented `module.exports` for the `Tree` class and used `const Tree = require('./index.js')` for importing\n3. **Understanding depth vs. height**: Clarified that depth is measured from the root down, while height is measured from leaves up\n\n## Skills Developed\n\n- Advanced array manipulation techniques\n- Module exporting and importing in JavaScript\n- Deep understanding of tree structures and traversal algorithms\n- Mastery of recursive functions and their application in tree operations\n\n## Reflections\n\nThis project provided invaluable insights into the inner workings of Binary Search Trees. Key learnings include:\n\n- The efficiency of BSTs in handling data insertion, deletion, and lookup\n- The critical role of recursion in tree operations and the importance of proper base cases\n- The distinction between breadth-first and depth-first traversals and their implementations\n- Practical experience with stacks and queues, particularly in level-order traversal using an empty array to `push()` and `unshift()` nodes.\n\nThe use of VSCode's debugging tools proved crucial in understanding recursive function flow and identifying issues quickly.\n\n## How to Use\n\n1. Clone the repository:\n   ```\n   git clone https://github.com/SReddy-96/TOP-binary-search-tree.git\n   ```\n\n2. Navigate to the project directory:\n   ```\n   cd TOP-binary-search-tree\n   ```\n\n3. Run the script (if using Node.js):\n   ```\n   node index.js\n   ```\n\nFeel free to explore the code and test the various methods implemented in this Binary Search Tree project!\n\n### Resources\n\n- [Removing duplicates from an array in JavaScript](https://builtin.com/software-engineering-perspectives/remove-duplicates-from-array-javascript)\n- [Traversing a Binary Search Tree in JavaScript](https://medium.com/@dondeveloper/algorithms-with-javascript-traversing-a-binary-search-tree-476e7dae9d88)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsreddy-96%2Ftop-binary-search-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsreddy-96%2Ftop-binary-search-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsreddy-96%2Ftop-binary-search-tree/lists"}