I have trouble understanding how you get to determine the time complexity of this algorithm (written in Python, but would suit any language):
def permutazioni(list):
n = len(list)
if n == 1 or n == 0:
return [list]
else:
risult = []
for i in range(n):
primo = list[i]
listaDegliAltri = list[:i] + list[i + 1:]
perms = permutazioni(listaDegliAltri)
for perm in perms:
risult.append([primo] + perm)
return risult
This procedure takes as input a sequence and returns as a result a sequence of sequences containing the set of all possible permutations of the starting sequence.
Example: permutations([a, b, c]) = [[a, b, c], [a, c, b], [b, a, c], [b, c, a], [c, a , b], [c, b, a]]
Now, to determine the complexity, I have to write and solve the equation of recurrence. When the list is long 0 or 1, no operations are performed. Otherwise, you run a cycle of n iterations in which each iteration the function is called on a list with one element shorter than (n-1) and then you run an inner for long n-1.
The professor then wrote:
T(0) = T(1) = 1 (1 why? Is it the cost of the return or other?)
T(n) = n*(T(n-1) + (n-1)) for n>1
Then he says that chooses the lower boundary and then writes (hereafter I did not understand anything):
T(n) > n*T(n-1)
from which:
T(n) > nT(n-1) > n(n-1)T(n-2) > n(n-1)*(n-2)*T(n-3)> ... > n!
That is:
T(n) = Ω(n!)
I did not understand because it has eliminated the (n-1) and because it has put the major instead of the equal sign. So I didn't understand anything. Someone explain it to me would know? Thank you