Diagnostic Quiz
Problems
1. Tower of Hanoi
Disk
i-1
is moved twice the number of times of Diski
It is correct. This can be reasoned using the recurrence relation for the Tower of Hanoi problem.
5. Time Complexity for Nqueens
Consider the solution to N-Queens given in class. Suppose the running time of
nqueens
is . What is ?
This is an awesome question. happens when we reach the base case, so here we need to think about what will happen in the base case.
The base case is:
It calls threaten_each_other_diagonally
which runs in .
And print a string with length n
takes . So, the overall running time for is .
Last updated