Algoritme & struktura të dhënash

Iterative vs recursive

Në shqip: Përsëritja dhe rekursioni

ShpjegimiSQ

Shumë probleme mund të zgjidhen me cikël (iterativ) ose me një funksion që thërret veten (rekursiv). Rekursioni është shpesh më i lexueshëm për pemë dhe grafe; cikli zakonisht përdor më pak memorie dhe s'rrezikon stack overflow.

EnglishEN

Many problems can be solved with a loop (iterative) or a function that calls itself (recursive). Recursion is often more readable for trees and graphs; a loop usually uses less memory and doesn't risk a stack overflow.

Si ta mendosh

Si ngjitja e shkallëve: mund t'i numërosh hap pas hapi (cikël), ose t'i thuash vetes „ngjit një, pastaj bëj sërish të njëjtën gjë“ (rekursion).

Lexoje në anglisht

Like climbing stairs: count them step by step (a loop), or tell yourself “climb one, then do the same again” (recursion).

Terma të lidhur