Search code examples
algorithmrecursionproof

How does my professor come up with the recursive case in this algorithm analysis?


My professor gave us the following explanation for the recursive algorithm for finding the permutations of a set of numbers:


enter image description here


When he has (T(m+1), n-1)) where does that come from? Why is it m+1 and n-1? I'm really confused as to where that comes from.


Solution

  • As he said, m represents the current size of P and n represents the size of S, in each recursive call you remove a number from S and add it to P, thus the size of your current permutation is increased by 1 (m+1) and the number of available numbers to add to the permutation is decreased by 1 (n-1)

    Note that it is multiplied by n as you perform this action for each number in S.