BinarySearchTree in java


What is BinarySearchTree in java and how it works. What are advantages, disadvantages of using it. any simple sample code of its working highly appreciated. thanks in advace. i have not clearly understood root, left, right then assigning lower to left all this concept related to real world applications. please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
A binary tree is a way to order data. It's a basic computer science concept. It is not a part of Java. Some Java objects (e.g. TreeMap) may be implemented as a binary tree.

It allows you to insert or locate data in log base 2 time.

Root is where you start your search for inserting or locating data.

Left points to data that is <= to the data in root.

Right points to data that is >= to the data in root.

An example of how it's used: Read data from some source (e.g. a file) and store it in memory for fast lookup or access in sorted order.

The TreeMap Java class is implemented as a binary tree, but it hides the implementation details from you. So you can get the first item (smallest value) in the list and iterate through the list.

You can find many code examples if you search for "binary tree java"

This page has a good explanation with diagrams.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.