I have the following problem:
Calculate the combination of three digits number consisting of 0-9, and no duplicate is allowed.
As far as I know, combinations don't care about ordering, so 123
is equal to 312
and the number of possible combinations should be
( 10 ) = 120 combinations
( 3 )
that said: I know how to calculate permutations (via backtracking) but I don't know how to calculate the combinations.
Any hint?
Finding the comnbination is also done via backtracking. At each step - you "guess" if you should or should not add the current candidate element, and recurse on the decision. (and repeat for both "include" and "exclude" decisions).
Here is a jave code:
You can run it with the following demo:
And get a series of combinations, and at the number of combinations printed (unsurprisingly, 120)