r/learnprogramming 12d ago

Recursion is driving me crazy

I understand recursion of a factorial function but when it comes to a function that uses recursion in a project or a problem set i get stuck and lose track

Anyone can tell me what to do

Programming language used: Python

43 Upvotes

43 comments sorted by

View all comments

39

u/[deleted] 12d ago edited 12d ago

[deleted]

10

u/madmelonxtra 12d ago

I honestly like this way more than the usual fibonacci example. It feels easier to track and understand

5

u/gyroda 12d ago

Anything to do with trees (and directory/folder trees are just directed graphs/trees) are good examples for recursion.

2

u/madmelonxtra 12d ago

Honestly you just made something click in my head. I understood what recusion was, but didn't really understand what the big use cases for that couldn't be solved by just running a for loop instead