2.43 Exercise 2.43
In the original procedure, queen-cols is recursively called once for a board size of k - 1. In Louis’ version, it is called k times. Because it produces the same result every time, Louis’ version of queens will still work. However, these extra calculations will make the procedure much slower. When running (queens 8), (queen-cols 7) will be called 8 times. In each of these calls, (queen-cols 6) will be called 7 times, &etc.
To estimate the difference in running time, let’s make a few simplifications to get upper bounds on the amount of time that these procedures can take. Suppose that every recursive call to queen-cols except the base case takes the same time as a call to (queen-cols 8), since none are any worse than this, and that we call this time S. There are then 8 calls to queen-cols in the original procedure, leaving a runtime of approximately 8S.
Noting that every non-leaf node in the recursion tree of Louis’ procedure has no more than 8 children, we can find an upper bound on this by supposing that they all have exactly 8. We then have something on the order of S + 8(S + 8(S + 8(...))) time, or approximately (8^8)S.