Home/Blog/Exams & Theory

Fibonacci Sequence in Structograms: Iterative vs. Recursive

2026-11-226 min read

Two Variables Are All You Need

Tracking just the previous two Fibonacci values (a and b) in a for loop yields linear O(n) time and O(1) space.

Live Example (DIN 66261)

Rendered directly in DIN 66261 — click to open and edit in the workspace.

fibonacci(n)Rückgabe: na = 0; b = 1naechste = a + b; a = b; b =naechstei = 2 bis nRückgabe: bn <= 1wahrfalsch

More Articles