jeffgerickson / algorithms

Bug-tracking for Jeff's algorithms book, notes, etc.
7.88k stars 1.02k forks source link

[Oops.] Time complexity of peasant multiplication #262

Open pooyataher opened 2 years ago

pooyataher commented 2 years ago

The error is present in the most recent revision.

Chapter number and Note title: Chapter 0 0.6 Analyzing algorithms Running time

Page number: 16

Error description: The trailing constant in the recurrence for the time complexity of PeasantMultiply is not correct.

Suggested fix: In the paragraph before the last, the expression

T(x, y) <= T([x/2], 2y) + 2

should be replaced with

T(x, y) <= T([x/2], 2y) + 4

because at each iteration (or function call, in case of the recursive version) of PeasantMultiply, we perform the following tasks.

Therefore, at one iteration, we perform at most four operations. Analyzing the recursive formula for x times y given on page 16 yields the same result, too.

Obviously, this change in the trailing constant of the recurrence will not change the asymptotic upper bound which is T(x, y) = O(log x) anyway.