Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-27-2009, 08:40 PM   #1
Member (10 bit)
 
faint545's Avatar
 
Join Date: Mar 2006
Location: Maryland
Posts: 550
Binary Search Tree Problem

So i've been enrolled in another computer science class and this one is about data structures and algorithms. We've been assigned a programming assignment to turn a completely unorganized/unstructured binary search tree into a balanced tree.

We're given 15 elements (I chose integers) and I decided to build a linear tree of those 15 integers. From there I'll have to pick the midpoint and then set that as a root and then perform a "rotate" to balance the tree out.

I'm kind of stuck at the point where I'm building a linear tree. For some reason I cant figure out how to make each element point to the next... (i.e. 1 -> 2 -> 3 -> 4 -> ...)

I've been able to assign the 1st integer to root and the 2nd to root.left but from that point I cant seem to figure out how to get the 3rd integer to be assigned to the 3rd left node in the tree and so on. Can someone provide me with an example in JAVA, not a pseudo code?
__________________
Kerberos2:
Corsair Obsidian 700D
ASUS M4A89TD
Radeon HD 5850
A-DATA 8GB DDR3 1333
AMD Phenom II x6 1055T @ 2.8GHz w/ Corsair H50
Corsair 850HX PSU
WD Blue 160GB 7200 RPM SATA HDD
WD Black 640GB 7200 RPM SATA HDD
ASUS DVD/CD Drive
faint545 is offline   Reply With Quote
Old 10-29-2009, 05:43 PM   #2
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
This is a common problem/question, and you can find implementations of this sorting algorithm by googling for java and binary search.

If you have a problem with a specific piece of the code, feel free to post back here.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Force Flow is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:44 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2