Generate combinations and permutations
Encode whether order matters, and avoid equivalent duplicate-value branches.
Understand the idea
A combination uses strictly increasing chosen indices so the same group is not generated in different orders. A permutation fills ordered positions using any unused input index. Mark an index before recursion and unmark it on return.
Trace a small example
Choosing two of A, B, C gives combinations AB, AC, BC. Ordered selections also include BA, CA, CB. For a sorted multiset [1, 1, 2], unique permutation generation skips an equal candidate when the previous equal index is not already used on the current path.
Conditions and cost
Distinct full permutations number n!, and output costs O(n × n!). Duplicate skipping applies at one decision depth, not by forbidding equal values everywhere. A used table tracks input positions, not numeric values.
How many length-2 combinations of three distinct items exist?
Turn the idea into code
List the unique full permutations of [1, 1, 2].
Give me a hint
Equal copies may not create duplicate sibling choices.
Show the explained solution
112, 121, and 211. There are 3 unique results, although the two labelled copies would create 6 positional permutations.
Your notes
Mark complete when you can explain it yourself.