Skip to content

Haminimi/binary-search-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Balanced Binary Search Tree

Description

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.

Live Preview

Open up your developer console to see some of the binary search tree methods in action.

Methods

  • 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

Tech

The project is built with:

  • HTML
  • Vanilla JavaScript

Tools

  • Visual Studio Code
  • Git

Covered Topics

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

Reflection

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. 😄

Credits

Happy coding!