Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 recursion
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tubs




PostPosted: Mon Nov 28, 2005 8:40 pm   Post subject: recursion

I don't understand quite how to approach this problem, any tips for getting started?

Using recursion, determine all two-letter subsets of a given string of characters. ex. {abcd} would have the subsets of:

{ab}
{ac}
{ad}
{bc}
{bd}
{cd}
Sponsor
Sponsor
Sponsor
sponsor
1of42




PostPosted: Mon Nov 28, 2005 10:18 pm   Post subject: (No subject)

Well, with recursion, dunno, but here's an answer for the NUMBER of subsets Wink (this assumes that order of characters doesnt matter):

(length(string)!)/((length(string)-2)!2!)

Razz

And then, define ! (factorial) recursively, and loop thru all the letters of the string, making the necessary combinations Very Happy

And there you are, you've determined them all (and the number of them), and used a bit of recursion Very HappyVery Happy
bugzpodder




PostPosted: Mon Nov 28, 2005 10:30 pm   Post subject: (No subject)

i dont see what number of subsets have to do with anything.

for recursion:
pick the first alphabet, say 'c'

call ur recursive function with the smaller alphabet set (make sure you remove all the alphabet before the one you picked as well) so in this case you call ur recursive function with {d} by removing a,b,c
1of42




PostPosted: Mon Nov 28, 2005 10:32 pm   Post subject: (No subject)

bugzpodder wrote:
i dont see what number of subsets have to do with anything.

for recursion:
pick the first alphabet, say 'c'

call ur recursive function with the smaller alphabet set (make sure you remove all the alphabet before the one you picked as well) so in this case you call ur recursive function with {d} by removing a,b,c


well, they don't have anything to do with anything, btu you use ! to find them, and therefore can define ! recursively, thereby satisfying the recursive usage requriement, and then solve the rest of the problem iteratively Very Happy
Hikaru79




PostPosted: Mon Nov 28, 2005 10:38 pm   Post subject: (No subject)

1of42 wrote:
bugzpodder wrote:
i dont see what number of subsets have to do with anything.

for recursion:
pick the first alphabet, say 'c'

call ur recursive function with the smaller alphabet set (make sure you remove all the alphabet before the one you picked as well) so in this case you call ur recursive function with {d} by removing a,b,c


well, they don't have anything to do with anything, btu you use ! to find them, and therefore can define ! recursively, thereby satisfying the recursive usage requriement, and then solve the rest of the problem iteratively Very Happy

Why would you go out of your way to sneak past a requirement that is in there to help you in the first place? Razz
Tubs




PostPosted: Tue Nov 29, 2005 10:09 am   Post subject: (No subject)

I'm doing this in C btw, sorry about that.
MysticVegeta




PostPosted: Wed Nov 30, 2005 3:05 pm   Post subject: (No subject)

Well if you need the concept understanding of the permutations possible. There is an excellent example by zylum in his recursion tutorial post in the turing tutorials. All you have to do is convert the code in C.. Smile
Tubs




PostPosted: Wed Nov 30, 2005 3:41 pm   Post subject: (No subject)

Ya, I figured it out. Thanks Smile
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: