Algorithm or Code for Possibilities
-
Is there an algorithm where i could get all the possible sequence? Example: given is "abc" where the possible sequence are: "abc" "acb" "bac" "bca" "cba" "cab"
Hi,
Silvyster wrote:
Is there an algorithm where ...
Yes there is. In fact there are many. It is a nice occasion for a recursive one: to find a valid combination permutation of N symbols, first choose the leftmost symbol (a foreach loop could do that), then calculate the remaining collection and solve the problem for that smaller collection (with N-1 symbols) by recursion. If you keep the symbols ordered in some way (say alphabetical) the nice side-effect is all combinations permutations will come out in the same (alphabetical) order. And recursion is appropriate since the number of combinations permutations grows exponen- tially with the word length, i.e. your patience will run out long before you get a stack overflow. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
modified on Friday, October 31, 2008 8:31 AM
-
Is there an algorithm where i could get all the possible sequence? Example: given is "abc" where the possible sequence are: "abc" "acb" "bac" "bca" "cba" "cab"
-
What you are looking for is an algorithm for permutations. Go forth and search the web. :)
Despite everything, the person most likely to be fooling you next is yourself.