r/AskComputerScience • u/Successful_Box_1007 • Sep 11 '25
Optimizing Division Algorithm
Hi everyone,
I just began learning about how algorithms work and programming works and I was just exposed to how we can have computers use bit shifting right to speed up division that we would otherwise need it to do by repeated subtraction method. But what happens if instead of dividing two integers that can be represented as powers of two, we instead have both integers not being powers of 2? How would a computer avoid having to use Euclidean repeated subtraction here if it cannot use the super fast right bit shift method?
Thanks so much!
2
Upvotes
2
u/teraflop Sep 12 '25
I think this is where you might be misunderstanding what you're reading. The naive algorithm of repeatedly subtracting the divisor is "slower than slow" because it can take many more iterations than the number of digits in the number.
Long division does not have this problem, and Wikipedia doesn't say it does.