A Critique of the Proposed National Education Policy Reform
5 2
1.
2. Function Analysis for call fib(5) fib(5) fib(4) fib(3) fib(3) fib(2) fib(1) fib(0) fib(2) fib(1) fib(0) fib(1) fib(2) fib(1) fib(0) fib(1) public static int fib( int n) if (n == 0 || n == 1) return n else return fib(n-1) + fib(n-2) 1 1 1 1 1 0 0 0 1 1 2 1 3 2 5
3.
4.
5.
6.
7.
8.
9.
10. Box trace of writeBackward(“cat”, 3) The initial call is made, and the method begins execution: s = “cat” size = 3 s = “cat” size = 3 s = “cat” size = 2 s = “cat” size = 1 s = “cat” size = 2 s = “cat” size = 3 A A A Outputline: ta Point A is reached, and the recursive call is made. The new invocation begins execution: Outputline: t Point A ( writeBackward(s, size-1)) is reached, and the recursive call is made. The new invocation begins execution:
11. Box trace of writeBackward(“cat”, 3) Output line: tac Point A is reached, and the recursive call is made. The new evocation begins execution: s = “cat” size = 3 s = “cat” size = 2 s = “cat” size = 1 s = “cat” size = 0 s = “cat” size = 0 s = “cat” size = 1 s = “cat” size = 2 s = “cat” size = 3 A A A A A A This is the base case, so this invocation completes. Control returns to the calling box, which continues execution:
12. Box trace of writeBackward(“cat”, 3) This invocation completes. Control returns to the calling box, which continues execution: s = “cat” size = 3 s = “cat” size = 2 s = “cat” size = 1 s = “cat” size = 0 s = “cat” size = 0 s = “cat” size = 1 s = “cat” size = 2 s = “cat” size = 3 A A A A A A This invocation completes. Control returns to the calling box, which continues execution: This invocation completes. Control returns to the statement following the initial call.