When Arithmetic Is Treated as Constant Cost

Some algorithm models count operations on a fixed-size word in constant time. Large integers can require work on many words.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compare two additions
  2. State why the model fits
  3. Relate numeric magnitude to the representation length
  4. Report the units of \(n\)

Compare two additions

Adding two ordinary small counters can fit native words. Adding two thousand-digit integers can touch many digits and return a similarly large number. Fixed-width and arbitrary-precision integers explain the representation difference.

State why the model fits

An array index bounded by the available machine memory usually needs a word-sized operation under conventional assumptions. A factorial result may not fit that model. Bit complexity makes encoded length part of the cost.[1]

Relate numeric magnitude to the representation length

Adding one to an unsigned word may be a single fixed-width instruction, with wraparound for an overflowing mathematical result. Adding one to an arbitrary-precision integer may propagate through many stored digits. State what operations and overflow behavior your algorithm assumes. See bounded and unbounded integers.

Binary 011111 + 1 = 100000
Carry propagates across five trailing one bits
Growing the number of bits grows possible propagation length

Report the units of \(n\)

When analyzing a number-theoretic routine, \(n\) might count input bits, machine words or the integer value itself. These are different scales. A loop of \(x\) iterations is exponential in the binary length of large positive \(x\).

References

  1. Jeff Erickson, Algorithms ↩