subset algo, hash table

S

someguy

Hi,
I'm trying to write a method in Java that takes in a string and
prints all the subsets (For example, if you are given "ABC", you would
print: A B C AB AC BC ABC). Any suggestions?

Also, how could a linked list and a hash table be combined to allow
someone to run through the list from item to item while still maintaining
the ability to access an individual element in O(1) time?

TIA
 
C

Carl Howells

someguy said:
Hi,
I'm trying to write a method in Java that takes in a string and
prints all the subsets (For example, if you are given "ABC", you would
print: A B C AB AC BC ABC). Any suggestions?

Also, how could a linked list and a hash table be combined to allow
someone to run through the list from item to item while still maintaining
the ability to access an individual element in O(1) time?

Homework, eh?

For the first, I like recursion. It's natural, clean, and very simple
conceptually.

For the second, you just combine the two structure in the obvious manner.

I hope nobody gives you any better answers than these... It'd be better
if you learned how to think on your own.
 
O

Oscar kind

Carl Howells said:
For the first, I like recursion. It's natural, clean, and very simple
conceptually.

In this particular case, I disagree: a nested loop is just a tad easier.
It's a close call though, so I'll implement your idea just for kicks.
 
O

Oscar kind

Oscar kind said:
In this particular case, I disagree: a nested loop is just a tad easier.
It's a close call though, so I'll implement your idea just for kicks.

Ok, in case the OP was asking a homework question, the deadline will have
expired by now. So to make good on my big mouth: it's implemented in the
PowerSet class in the playground project you can find here:

http://home.hccnet.nl/okind/java/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top