recursion - How does the algorithm for recursively printing permutations of an array work exactly? -


i can't understand how algorithm works. explanations i've seen if have set such {a, b, c} , want permutations, start each letter distinctly, find permutations of rest of letters. example {a} + permutationsof({b,c}).

but explanations seem gloss on how find permutations of rest. example being this one.

could try explain algorithm little more me?

to understand recursion need understand recursion..

(c) programmer's wisdom

your question fact, "permutations of rest" recursive part. recursion consist of 2 parts: trivial case , recursion case. trivial case points case when there's no continue recursion , should returned.

in sample, trivial part {a} - there's 1 permutation of set - itself. recursion part union of current element , "rest part" - i.e. if have more 1 element, result union of permutation between element , "rest part". in terms of permutation: the rest part current set without selected element. i.e. set {a,b,c} on first recursion step {a} , "rest part": {b,c}, {b} , "rest part": {a,c} - and, finally, {c} "rest part": {a,b}

so recursion last till moment when "the rest part" single element - , end.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -