Time complexity and recurrence relation for maximum number of A’s using given four keys

87 Views Asked by At

I am wondering if someone can help me figure out the recurrence relation for maximum number of A’s using given four keys problem. The following is the code fragment

int maxCharacterFor(int N) {
   if (N <= 6) return N;

   int maxChars = 0;   
   for (int b=N-3; b>=1; b--) 
        maxChars = Math.max(maxChars, (N-b-1)*maxCharacterFor(b));

   return maxChars;
}

I know it's definitely exponential and feels like very close to O(N!), but I am not sure if the following recurrence relation is correct or not. And how to analyze its run-time.

$$ T(n) =\sum\limits_{k=1}^{n-3} T(k) + O(n) $$