Solved

Can i use binary search tree in an unordered array?

Posted on 2013-01-25
7
703 Views
Last Modified: 2013-01-25
Hi there,

I have unordered array content and i want to have a search on that. So is it true that i have to sort my array first, "before" populating the tree?

Regards.
0
Comment
Question by:jazzIIIlove
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 38818306
It is true. Binary ordering/searching functionality has to be performed on sorted objects
0
 
LVL 27

Assisted Solution

by:d-glitch
d-glitch earned 100 total points
ID: 38818332
No.  In a binary search, every test should reduce the search range by half.
If the array is unordered, your test doesn't tell you which way to go.
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 100 total points
ID: 38818361
I agree with CEHJ - yes, you need to sort it first.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:d-glitch
ID: 38818371
I agree with CEHJ as well.

The No in my comment refers to the question in the title.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 38818385
Thanks, but a question,
http://www.youtube.com/watch?v=a0o7AWhKKCM
 In 0.06 of the video, the elements in the array are not presorted. I am a little confused.

Regards.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 38818447
The video i see is solely devoted to showing the ordering of the numbers
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 100 total points
ID: 38818479
This video shows only the right way to build the binary tree, nothing more! :-)
You dont need to order the source array at the begining, but it's good to do that in order to choose the right element to put as a root of the tree. In the video root element "5" is chosen as a root "randomly" but it is very important because the rest 6 elemnts are : 3 bigger than 5 and 3 less than 5, so the tree is BALANCED by default.
If your array is not sorted at the beginning, you will be able to build the tree, but after that you need to balance it, in orer to have best performance for search operation.
see this: http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree
Btw, Java offers implementatio of this structure, but yes, it's good to know how it works.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question