Skip to content

An application that compares tree data structure i.e. BST, AVL, Btree.

Notifications You must be signed in to change notification settings

Zain-Bin-Arshad/Tree-DataStructure-Comparison

Repository files navigation

Tree-DataStructure-Comparison

You have learned about Tree data structure. Now, you will be guessing that there are various tree available, what is the benefit of one on other, which tree is fast on the given data set. Well, this project will answer all of your confusions. We will be talking about the three famous trees:

  1. Binary Search Tree (BST)
  2. AVl Tree
  3. Btree

How to run?

Just compile everything using javac *.java. Now run the file TreeProfiler.java. start

As you can see there are two modes, I ma going to explain both don't worry mate. If you are worrying about entering some invalid data or choosing invalid option, then, my code will help you. I have done Exception handling to a very far extent.

Interactive Mode

In this mode you can control the program flow, get what you need whenever you need. I am using BST by default in the interactive mode, but you can change it easily in the code. Interactive mode looks like this: int

Load New Data

As the name says, if you want to built a tree you have to use this option. This further gives you two more options: load

Stock

Stock data means the data inside the data.txt file. This data actually reflects an account data and is in this format:

Ticker, Date, Open, High, Low, Close and Volume

stock

If you want to play with the input data, you have to change the AccountData.java file and data reading code in TreeProfiler.java

Saved

Lets say you have loaded a tree and made some changes into the tree, afterwards you saved the tree. If you want to use that saved tree you can use this option.

ved

Tree Find

If you want to find a specific key in the tree, you can make use of this option. Isn't this all trees about ? Save, retrieve huh ? find

Tree Insert

Want to insert a new value in the tree? Well you can using this option.

insert

Let's check whether the value got inserted or not. It's inserted!

found

Tree Delete

Want to delete that unwanted node, go with this option.

delete

Check whether "ABC123" got deleted or program is messing with us. Well, it's deleted !

del check

Tree Statistics

Here comes the main feature, you want to know how good your tree performed? and want to save the result in a text file for later contrast and comparison?

  • How much time it took to build the tree?
  • What is the size of you tree?
  • What is the height of your tree?
  • How much percent your tree is balanced?

Wait no more... Just want to remind that as we are using BST in interactive mode, which is an unbalanced tree. Hence, the balance % will be 0.

stsa

This is how BST_stats.txt

bst st

Save Tree

After making some great changes to the tree, you want to save it for later use. Well, you have this option also. The tree object will be saved as a serialized object.

saved

Quit

Mastered Tree data structure in java and want to quit? This option is for you then.

Profiler Mode

In this mode you can compare the performance of a tree automatically, results will be stored in a text file for comparison if user wants. You have to specify the input data filename and tree type as a command line argument.

simu

Similarly, you can compare the performance by using different tree and data structure. The "AVL_stats.txt" will look like this:

avl

Thanks

I would like to thank my teacher Sir Nadeem Ghafoor Chuadhary, for every impact he had in my life, let it be "Programming", "Ideological", "Personal" many more.