A balanced binary search tree with all the basic methods. The project is a part of The Odin Project's curriculum. The Odin Project provides a high quality web development education maintained by an open source community.
Open up your developer console to see some of the binary search tree methods in action.
- insert: accepts a value to insert
- delete: accepts a value to delete
- find: accepts a value and returns the node with the given value
- levelOrder: accepts a random optional callback function as its parameter, traverses the tree in breadth-first level order and provide each node as an argument to the callback, if no callback is given as an argument it returns an array of values
- inOrder, preOrder, and postOrder: functions that also accept a random optional callback as a parameter, they traverse the tree in their respective depth-first order and yield each node to the provided callback, if no callback is given as an argument, they return an array of values
- height: accepts a node and returns its height
- depth: accepts a node and returns its depth
- isBalanced: checks if the tree is balanced
- rebalance: rebalances an unbalanced tree
- prettyPrint: console.log the tree in a structured format
To Do:
- Try to improve and optimize the methods
The project is built with:
- HTML
- Vanilla JavaScript
Tools
- Visual Studio Code
- Git
This section mentions the main topics covered during project work and prior lessons
- Algorithms and Data Structures
- Time and Space Complexity
- Binary Search Algorithm
- Breadth First Search and Depth First Search
- Linked List
- Balanced Binary Search Tree
The levelOrder and height methods are implemented using both the iterative and recursive approaches. For other methods, I have chosen what is in my opinion the better approach for each particular method.
I love to see a tree printed in the console. 😄
- Icon used for the favicon image is one of the Hierarchy icons created by Freepik - Flaticon.