On Geeks for Geeks the following problem is analysed:
Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return the minimum number of jumps to reach the end of the array (starting from the first element). If an element is 0, they cannot move through that element. If the end isn’t reachable, return -1.
The recursive solution to this problem is to recurse on every possible step from the current element and return the minimum jumps. So if the size of the array is N, then for the first element, we have N-1 steps (choices) to recurse on (which includes recursing on the second element) and then for the second element, we have N-2 steps to recurse on (which includes recursing on the third element)... and so on. So intuitively the time complexity should be (N-1)(N-2)(N-3)....1 which is N-1! or O(N!) in big-O notation.
But the time complexity at GFG is given as:
Time complexity: O(n^n).
There are maximum n possible ways to move from a element. So maximum number of steps can be N^N so the upperbound of time complexity is O(n^n)
I know that there is a high probability of me being wrong but where could I be wrong?