Discuss Binary Search Tree Problem in the Java Help forum on Dev Shed. Binary Search Tree Problem Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 87
Time spent in forums: 2 Days 2 h 17 m 7 sec
Reputation Power: 8
Quote:
Originally Posted by spazzzer
How would I write a recursive algorithm that returns the Binary Search Tree (BST) object containing the value argument and return null if the value cannot be found?
What I have so far is:
abstract class BST {
public int data;
public BST left;
public BST right;
static public BST find(BST root, int value);
}
then in another class where I define this method I have the method heading:
Posts: 1,229
Time spent in forums: 3 Weeks 4 Days 5 h 55 m 23 sec
Reputation Power: 617
Quote:
Originally Posted by spazzzer
Does anyone know how to solve this problem?
Yes.
You may want to take a look at this link. It will give you some assistance in restating your question in a way which will be more likely to elicit a more helpful response.
__________________ All science is either physics or stamp collecting. - Ernest Rutherford
Posts: 10
Time spent in forums: 59 m 8 sec
Reputation Power: 0
I have spent atleast a couple hours looking for a search algorithm for the binary search tree. I cannot seem to find one, that is why I am asking here. I figure someone here must know, . Anyone help PLEASE?
Posts: 10
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by tfecw
Why did you spend a couple of hours looking? The link i posted has the algorithem.
I spent acouple of hours looking when I first needed the algorithm. But the link you posted has a algorithm and its not recursive. The search algorithm they use is:
TreeSearch (x, k)
while x != NIL and k != key[x]
if k < key[x]: x <- left[x]
if k > key[x]: x <- right[x]
return x
Would my algorithm return the same result? (I am not sure, =/)
Posts: 10
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Well, that would mean making the entire Binary Search Tree algorithm, which is pretty big. The easiest way would be to find someone who knows this algorithm, and he could just read my 5 lines and tell me if it works or not . Does anyone know?
Posts: 2,748
Time spent in forums: 3 Months 1 Week 3 Days 6 h 49 m 8 sec
Reputation Power: 1569
Quote:
Well, that would mean making the entire Binary Search Tree algorithm, which is pretty big. The easiest way would be to find someone who knows this algorithm, and he could just read my 5 lines and tell me if it works or not . Does anyone know?
...
If you don't plan on implementing the rest of the tree, why are you trying to write the search?
Posts: 10
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Because I am using the search algorithm from the binary search tree, but it is more like a hybrid algorithm used for something else. Does anyone know if my 5 lines are correct or not? =/, I never though it would be this hard to find a simple answer. The reason I want to be so certain is because I dont want to have debugging issues down the road.
Posts: 2,748
Time spent in forums: 3 Months 1 Week 3 Days 6 h 49 m 8 sec
Reputation Power: 1569
Quote:
Because I am using the search algorithm from the binary search tree, but it is more like a hybrid algorithm used for something else.
Then why not test it with your something else that you do plan on implementing
Quote:
The reason I want to be so certain is because I dont want to have debugging issues down the road.
Debugging is a part of programming. Writing your own test code goes a long way in terms of simplifying debugging. It's how i'd test your code. So i I'm a little curious why I, or someone else should i spend the time writing that code, to test your function? This is a very important skill that you might as well learn now, so you'll be equipped with the knowledge to test the next thing you write. You came up with your initial algorithm, so why not try coming up with something that tests it?
Last edited by tfecw : March 15th, 2006 at 12:36 PM.
Reason: even i was embarrassed by the lack of spelling skills...
Posts: 10
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by tfecw
Then why not test it with your something else that you do plan on implementing
Debugging is a part of programming. Writing your own test code goes a long way in terms of simplifying debugging. It's how i'd test your code. So i I'm a little curious why I, or someone else should i spend the time writing that code, to test your function? This is a very important skill that you might as well learn now, so you'll be equipped with the knowledge to test the next thing you write. You came up with your initial algorithm, so why not try coming up with something that tests it?
I have plenty experience in the debugging department, I just did not want a cascading debugging problem like I have said before. I have also said that it would be easier for someone who knows the algorithm to take alook at my 5 lines of code, and tell me if it would work with a standard binary search algorithm. So if anyone could do this for me, I would be very grateful. Obviously tfecw cannot answer my question. I am asking this question to someone who knows the binary search algorithm. Thanks.