recursive function

Hi

iam new to java .i need help on the recursive algorithm ..I have a hashmap where value is a array list for eg:

key value

a->b ,c,d,e,f

b->i,j,k,l,m

d->f,p,q

i->u,w,x

v-> z,l

r-> 1,2,3,4

t -> ma,ku,sa

input to the program is "a" i need to look whether "a" has any value if it does for each value i need to look in the hashmap and find whether is has any value ,i need to go recursively to get all the elements .

output when string "a" is

a =b,c,d,e,f

b= i,j,k,l,m

i=u,w,x

d= f,p,q

I don't need any code but any help with recursive algorithm would really help

thanks for the help

[716 byte] By [kumsaaa] at [2007-11-26 16:00:27]
# 1
Let me make sure I get this, you look up a and get b,c,d,e,f. Then you want to look up the value list for each of those values b,c,d,e,f? Then repeat for each element in each result?
hunter9000a at 2007-7-8 22:21:51 > top of Java-index,Java Essentials,New To Java...
# 2

You've basically already described your recursive algorithm. Try coding it out now.

Note: you'll probably want to keep a set of "seen" keys, in case there are any loops from keys to values to keys, etc. (For example, if the key i had an a as one of its values.) There doesn't seem to be any loops now but I can imagine that it might in the future.

paulcwa at 2007-7-8 22:21:51 > top of Java-index,Java Essentials,New To Java...
# 3

here's some pseudo code:void printValues(key, map)

'value' = map.get(key)

for(every element in 'value')

display "'key' has 'value[i]'"

end for

for(every element in 'value')

printValues(value[i], map)

end for

end

prometheuzza at 2007-7-8 22:21:51 > top of Java-index,Java Essentials,New To Java...
# 4
Hi thanks yes that is right i need to look up for each vales and then repeat each element in each result
kumsaaa at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...
# 5
pls correct me if iam wrong this pseudo code will print only the values for bcdef but i need to get b's value which is ijklm now since i is a key i need to get i's valueswhich is uwx and u,w,x does not have any key so i need to stop here.thanks for the help
kumsaaa at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...
# 6
This is where the recursion come in. You need to recursively call the method passing b's list as a parameter.
floundera at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...
# 7
@kumsaCould you please reply / assign dukes in http://forum.java.sun.com/thread.jspa?threadID=5122594&messageID=9437396#9437396 ?
java_a at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...
# 8
> this pseudo code will print only the values for bcdef No - the second for loop ensures that the method is called againfor each of bcdef (and hence for each of their children etc).
pbrockway2a at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...
# 9
Sounds like you are trying to create a LR parser for a Context Free Grammar? Am I right? Or am I the only one reminded of my programming languages class by this question?
bheilersa at 2007-7-8 22:21:52 > top of Java-index,Java Essentials,New To Java...