Published by Dimitris Kougioumtzis · Updated
Test every candidate divisor in ascending order.
Scan candidates for exact divisibility, emitting each divisor and its contribution to the count.
When to use Divisor enumeration
A direct bounded divisor-enumeration baseline.
Choosing an alternative
Paired enumeration can stop at the square root.
Worked example: input and state changes
Example input
12
These checkpoints follow the actual example timeline. State details show the stored values and decisions; use the visualization to inspect every intervening step.
Step 0: Initial state.
State at this checkpoint
{ "values": [], "active": [] }Step 2: 2 divides 12.
State at this checkpoint
{ "values": [ 1, 2 ], "active": [ 1 ] }Step 4: 4 divides 12.
State at this checkpoint
{ "values": [ 1, 2, 3, 4 ], "active": [ 3 ] }Step 5: 6 divides 12.
State at this checkpoint
{ "values": [ 1, 2, 3, 4, 6 ], "active": [ 4 ] }Step 7: Divisors: 1, 2, 3, 4, 6, 12.
State at this checkpoint
{ "values": [ 1, 2, 3, 4, 6, 12 ], "active": [] }
Expected final state
Divisors: 1, 2, 3, 4, 6, 12.
Complexity and input bounds
Family: Number theory. Time complexity: O(n).
Space complexity: O(divisor count) output; O(1) scanning state.
Working-space bounds describe algorithm state and any explicitly noted output, excluding the visualization's saved timeline. Recording frames can use more memory than running the function alone. Here n is sequence length, V and E are vertex and edge counts, and other parameters refer to the named input dimensions.
One integer from 1 to 240.
The playground validates these limits before starting. Downloaded functions are callable implementations, with parameter and output-buffer contracts in their comments; they do not all repeat the playground's input validation.
Common mistakes and limitations
Do not assign a square-root bound to this full-scan implementation; paired methods must avoid duplicating a square root.
Further reading
For background on algorithm analysis and the JavaScript function interface:
- MIT OpenCourseWare: algorithm design and analysis foundations
- MDN: JavaScript function parameters and return values
Editorial and testing approach · Browse all algorithm guides
Complete JavaScript implementation
1 2 3 4 5 6 | // n from 1 to 240. Writes positive divisors in ascending order and returns their count. Reference snippets assume validated playground inputs. Fixed scratch buffers have 256 slots. Sorting variants may use a different traversal strategy than the animation. function algorithm(n, output) { let count = 0; for (let d = 1; d <= n; d++) { if (n % d == 0) { output[count++] = d; } } return count; } |
Source
No original paper has been verified for this entry. This source is a reference text or teaching reference, not an asserted original publication.
- The Art of Computer Programming, Volume 2: Seminumerical Algorithms (3rd edition)
Donald E. Knuth (1997). Reference book.