programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# partial permutation using queue

Ranch Hand
Posts: 32
Hey guys, I have an assignment and part of it is about getting the partial permutation of n numbers using LinkedQueue.
I started on the method but it keeps going on an infinite loop when I set s to an empty string (showed in the code by //here) but when I don't it only returns the variables for example if alphabet contains a,b,c,d it return abcd and that's it. I think it could be solved (or maybe not) when I change the while loop condition but I am not sure what to go with.

I have another method that will check for repeated variables that I will use when I am done with this method.

Ranch Hand
Posts: 934
4
What do you mean by partial permutation? Can you please explain further what do you want to do?

Marshal
Posts: 58462
178
Agree. Please write out the algorithm you intend to use.

Sheriff
Posts: 4756
133
Does getSize() ever return less than zero?

Mark Nasr
Ranch Hand
Posts: 32
Sorry for the lack of information. This is what is asked "given an alphabet of N symbols and a size SZ, generates all partial permutations of the alphabet that has the size smaller than or equal SZ."
and an example
"for alphabets {a,b,c,d}
size=3 alphabet size=4
a;b;c;d;ab;ac;ad;ba;bc;bd;ca;cb;cd;da;db;dc;abc;abd;acb;acd;adb;adc;bac;bad;bca;bcd;bda;bdc;cab;cad;cba;cbd;cda;cdb;dab;dac;dba;dbc;dca;dcb;"
From what I unndrstand is that getSize() (which is the size = 3 above) returns the size which is used to generate all the possible letter combinations up to that size number and the alphabet size is the size of the alphabet array which is given.
@Knute size should only return 1 or more

Campbell Ritchie
Marshal
Posts: 58462
178
Aha. Have you got an algorithm to create those permutations?

Why are you using a Queue?

Mark Nasr
Ranch Hand
Posts: 32

Campbell Ritchie wrote:Aha. Have you got an algorithm to create those permutations?

Why are you using a Queue?

No I have to create all the permutations in this method. I am using a Queue to hold the variables while going over the variables again in the for loop.
I should be using something similar to this method.

Mark Nasr
Ranch Hand
Posts: 32
My method should do something similar to this
a.png

Campbell Ritchie
Marshal
Posts: 58462
178
And do you understand what the diagram means?

author
Marshal
Posts: 23441
138

Mark Nasr wrote:My method should do something similar to this

Why don't you just print out each iteration to see exactly what is happening?? If you do, you will likely see something like this...

Henry

Mark Nasr
Ranch Hand
Posts: 32
I solved the problem thanks guys

Knute Snortum
Sheriff
Posts: 4756
133
How did you do it? Would you like to post what you did?

Mark Nasr
Ranch Hand
Posts: 32
This is the solution I found

Knute Snortum
Sheriff
Posts: 4756
133
Good job.

This:

can be this:

Campbell Ritchie
Marshal
Posts: 58462
178
And of course that way you are not using the == operator.