big o - Why is multiplication n^2 time? -
i've read operations such addition/subtraction linear time, , multiplication n^2 time. why true?
isn't addition floor(log n)
times, when n smaller operand? same argument goes subtraction, , multiplication, if make program long multiplication instead of adding integers together, shouldn't complexity floor(log a) * floor(log b)
, b operands?
the answer depends on "n." when addition o(n) , multiplication (with naïve algorithm) o(n^2), n length of number, either in bits or other unit. definition used because arbitrary precision arithmetic implemented operations on lists of "digits" (not base 10).
if n number being added or multiplied, complexities log n , (log n)^2 positive n, long numbers stored in log n space.
Comments
Post a Comment