Solved

Can i use binary search tree in an unordered array?

Posted on 2013-01-25
7
694 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
which object should i use (efficiency) 5 47
Need a complete list of ASP.NET page load events 3 29
Resolve Dependency Issues 4 47
expectj telnet failing 5 26
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now