Notes: Of the three problems given below, one will be solved by the TAs in next week's discussion section, you will have to solve one in class, and the remaining problem is due in the lecture on Friday, 4/7.
//********************************************** // Earlier I had tried board = oldBoard. I got // strange results. Why? //**********************************************
Once we realize that the current placement of the queen is not going to work, we want to restore the board to how it was earlier and try a new position for the queen. To do this, I kept a copy of board (called oldBoard) before I updated it and then if the current placement of the queen did not work, I want to restore board, by copying oldBoard back into it.
Without thinking too hard about this, in my first attempt, I simply used
board = oldBoard;and got strange results. You should try using this to see the results I got. Your task is to explain why I got those strange results.
int fibonacci(int n) { if((n == 1) || (n == 2)) return 1; else return fibonacci(n-1) + fibonacci(n-2); }
This function is not very useful for computing large Fibonacci numbers. For example, when I used it to compute the 50th Fibonacci number, it took about a minute and returned the following answer:
serv15.divms.uiowa.edu% java FibonacciTest Type a positive integer. 50 The 50th Fibonacci number is -298632863