• Post Reply Bookmark Topic Watch Topic
  • New Topic

partial permutation using queue  RSS feed

 
Mark Nasr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by partial permutation? Can you please explain further what do you want to do?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree. Please write out the algorithm you intend to use.
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does getSize() ever return less than zero?
 
Mark Nasr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha. Have you got an algorithm to create those permutations?

Why are you using a Queue?
 
Mark Nasr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My method should do something similar to this
a.png
[Thumbnail for a.png]
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And do you understand what the diagram means?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem thanks guys
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you do it? Would you like to post what you did?
 
Mark Nasr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the solution I found
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good job.

This:

can be this:
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And of course that way you are not using the == operator.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!