Let’s Guess… When n is even: T(n) = 2T(n-1) When n is odd: T(n) = 2T(n-1) + 1 Proving this directly is not obvious. However, a proof by induction is natural and easy. Logo Program to Experiment to chinese :n ; an inefficient recursive program if (= :n 1) op 1 if (= :n 2) op 2 op (+ 1 (chinese (- :n 1)) (* 2 chinese (- :n 2)) end to chinese2 :n ; a fast computation of the closed form if (= :n 1) op 1 if (= :n 2) op 2 if (even? :n) op (/(* 2 (-(exp 2 :n) 1)) 3) op (/ (-(exp 2 (+ :n 1)) 1) 3) end to exp :a :b make "x 1 repeat :b [make "x (* :a :x)] op :x end
Let’s Guess… When n is even: T(n) = 2T(n-1) When n is odd: T(n) = 2T(n-1) + 1 Proving this directly is not obvious. However, a proof by induction is natural and easy. Logo Program to Experiment to chinese :n ; an inefficient recursive program if (= :n 1) op 1 if (= :n 2) op 2 op (+ 1 (chinese (- :n 1)) (* 2 chinese (- :n 2)) end to chinese2 :n ; a fast computation of the closed form if (= :n 1) op 1 if (= :n 2) op 2 if (even? :n) op (/(* 2 (-(exp 2 :n) 1)) 3) op (/ (-(exp 2 (+ :n 1)) 1) 3) end to exp :a :b make "x 1 repeat :b [make "x (* :a :x)] op :x end