Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2005, 8:55 PM   #1
the_new_guy_in_town
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 the_new_guy_in_town is on a distinguished road
Question help with recursion problem

Hey everybody I am new in Java town and some “people” told me that in case of panic I can come here for help.
Well I am in PANIC. :eek:
The problem is that I can not think recursively that good and I am struggling with this little problem for some time now.
I need to generate all combinations of uppercase letters when given a group of starting letters. For example the combination of the first three letters of the alphabet ABC will generate ABC, AB, BC, A, B, C ( each string is in lexicographical order ) the number of combinations is (2^n )- 1 where n is the number of letters. So if I am given 4 letters the letters will be the first four letters of the alphabet ABCD and it will result in 15 combinations.

The problem needs to be solved recursively!!

Now I don’t want you guys to just give me the code, since it will be unethical and it will not help me on the long run, but if one of you can put me on the right track I will surely appreciate it.

Thank you in advance.
the_new_guy_in_town is offline   Reply With Quote
Old Apr 6th, 2005, 9:17 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Splitting it into an array of chars might help a little -- I find it easier to index that way. If you could be more specific as to how you need help, we may be able to help you better. Also, I don't know if you're allowed to use ArrayList, but if you are, that would probably help you tremendously if you combine it with a Collections.sort() method when sorting lexicographically.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Apr 6th, 2005, 11:21 PM   #3
the_new_guy_in_town
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 the_new_guy_in_town is on a distinguished road
Ok i put the string into an array the problem is how i do the recursion to group. I dont know if this will help some more but if i am doing 4 caracters i will have this result

A, AB, AC, AD, ABC, ABD, ABCD
B, BC, BD, BCD,
C, CD
D,

The format is not important, I put it like this so you guys can see it better.

I was thinking to make first an array of strings or ch (i guess strings is better)that will hold the letters

|0|1|2|3|
|A|B|C|D|

And then creat one more array of strings that will hold 2^4-1 = 15 combinations

Now i am stuck with the recursion part of the program on how to make the combinations.
the_new_guy_in_town is offline   Reply With Quote
Old Apr 7th, 2005, 3:04 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
take the first letter in the array and put it with all the ones after it in the array, then do the same with the second and third etc just alwyas going forward through the array and not in reverse,

hmmm the next part i would have those 2 letters you have stored and add a third letter etc to them making sure no repeats or seomthing like that,
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC