Solved

Can i use binary search tree in an unordered array?

Posted on 2013-01-25
7
708 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

733 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