Skip to content

contactsunny/Binary_Search_Tree_Implementation_Java_POC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

All data structures implementations

For a list of all the data structures I have implemented, click here.


Binary Search Tree Implementation POC in Java

This is a simple example of a binary search tree implementation in Java. We create a custom Node class which can take values of integer type. We also create a BinarySearchTree class which will hold the actual binary search tree.

We provide three major traversals for our binary search tree:

  • pre order traversal
  • in order traversal
  • post order traversal

Running the project

Once you clone this repo, cd into the project root directory and run the following command to compile and build this maven project:

mvn clean install

Once you run this command, Maven will build the project and keep it in the /target directory in the project root directory. You can run the program using the command below:

java -jar target/binary_search_tree_implementation_poc-1.0-SNAPSHOT.jar

Illustrating different traversals

For our example, we'll consider the following binary search tree, which is a very simple example:

Binary Search Tree Illustration

The following traversals are for this example binary search tree:

Pre order traversing:

In this type of traversal, we first traverse to the node, then the left child, then the right child. You can create a much longer tree in your example and find out how it functions when there are move levels.

10 7 5 8 15 12 18

In order traversing:

In this type of traversal, we first traverse to the left child, then the node, then the right child.

5 7 8 10 12 15 18

Post order traversing:

In this type of traversal, we first traverse to the left child, then the right child, and finally the node, .

5 8 7 12 18 15 10

About

This is a simple example of a binary search tree implementation in Java.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages