Exercise 1.26

Read Exercise 1.26 ~ Solution


(square (expmod base (/ exp 2) m)) evaluates (expmod base (/ exp 2) m) once and passes the value to square. As exp is halved for each recursive call the time is O(log2 exp).

(* (expmod base (/ exp 2) m) (expmod base (/ exp 2) m)) evaluates (expmod base (/ exp 2) m) twice before passing both values to square. So the running time is O([log2 exp]2) or which is O(exp).

Leave a comment