Division By Repeated Subtraction
The simplest division algorithm, historically incorporated into a greatest common divisor algorithm presented in Euclid's Elements, Book VII, Proposition 1, finds the remainder given two positive integers using only subtractions and comparisons:
while N ≥ D do N := N - D
end
return N
The proof that the quotient and remainder exist and are unique, described at Euclidean division, gives rise to a complete division algorithm using additions, subtractions, and comparisons:
function divide(N, D) if D == 0 then throw DivisionByZeroException end if D < 0 then (Q,R) := divide(N, -D); return (-Q, R) end if N < 0 then (Q,R) := divide(-N, D); return (-Q - 1, D - R) end // At this point, N ≥ 0 and D > 0 Q := 0; R := N while R ≥ D do Q := Q + 1 R := R - D end return (Q, R)
end
This procedure always produces R ≥ 0. Although very simple, it takes Ω(Q) steps, and so is exponentially slower than even slow division algorithms like long division. It is useful if Q is known to be small (being an output-sensitive algorithm), and can serve as an executable specification.
Read more about this topic: Division (digital)
Famous quotes containing the words division and/or repeated:
“Affection, indulgence, and humor alike are powerless against the instinct of children to rebel. It is essential to their minds and their wills as exercise is to their bodies. If they have no reasons, they will invent them, like nations bound on war. It is hard to imagine families limp enough always to be at peace. Wherever there is character there will be conflict. The best that children and parents can hope for is that the wounds of their conflict may not be too deep or too lasting.”
—New York State Division of Youth Newsletter (20th century)
“Lift not thy spear against the Muses bower:
The great Emathian conqueror bid spare
The house of Pindarus, when temple and tower
Went to the ground; and the repeated air
Of sad Electras poet had the power
To save the Athenian walls from ruin bare.”
—John Milton (16081674)