To be noted: the drawing in exercise 1.14 is unfinished. I did it in a notebook, but haven't yet had the time to put it in a txt file.
10 lines
438 B
Text
10 lines
438 B
Text
Essentially, instead of us halving the time of computation,
|
|
every time we have an even number, we instead halve the expmod call
|
|
but then, make that call twice, in other words, instead of
|
|
(specifically for even number):
|
|
T(n) = O(1) + T(n/2)
|
|
we get:
|
|
T(n) = O(1) + 2*T(n/2), which is going to give us roughly:
|
|
O(n)
|
|
We get a recursion tree, growing exponentially with at every recursive call,
|
|
of which there are O(log n), so exp(log(n)) = n.
|