Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can i use binary search tree in an unordered array?

Posted on 2013-01-25
7
Medium Priority
?
730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 800 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 400 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 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 400 total points
ID: 38818361
I agree with CEHJ - yes, you need to sort it first.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 800 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

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.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

609 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