Infinitely Nested Loops

preview_player
Показать описание
Just wanted to share some perspective on recursion.
Рекомендации по теме
Комментарии
Автор

imagine using recursive algorithms in 2023. --stack and queue based solutions gang

lame_lexem
Автор

Big O (∞) my favorite style of pro-gramming

Tntpker
Автор

Agree. Code duplication is also powerful tool and concept. For example, you may accidentally forget the function definition, parameters number, return type etc. With code duplication you always know in place which code you are going to execute. Reject code reusing, embrace infinite loops and code duplication!

vasylvoina
Автор

Lists in haskell are monads and the fun thing is if you use the do notation on them, every line of code enters a new nested loop!

marusdod
Автор

Infinite... well, as long as the stack can hold the function calls that is haha.

tralphstreet
Автор

This is why computers aren't Turing-complete. They're finite state machines.

Lemon_Inspector
Автор

Don't be afraid of the nested loops

LogicEu
Автор

The option to infinitely nested for loops is powerful, but is also wasteful in terms of memory footprint
IMO, if you find yourself using a recursion, you might want to look for a different data structure unless absolute necessary

avi
Автор

Recursive functions are the only way I’ve done that so far out of their simplicity, but returning a value from the 150th nested version of a function to the first is at least 150 operations that might be somewhat tedious to inline (compilers are smarter than me so correct me if there is an optimization for that kind of thing), but every once in a while, super high levels of recursion end up giving me a segfault unless I make it a void function and just adjust an answer variable in memory when I get there and then terminate the functions

blazingazong
Автор

And there are ways to traverse an arbitrary tree without recursive functions or nested loops.

daggerball
Автор

Nesting loops is good. But I saw infinite recursion listed as a vulnerability somewhere. Maybe you could do a video on why that would be so. If for instance someone gave a huge number of items to be iterated over or recursed would that then present a problem where the program hangs?

brocksprogramming
Автор

So, you actually store a tree as a linked list? That's inefficient in multiple ways. The better method is to use a 1D array. Better for cache, better for the compiler to optimize, better for using fewer loops, and without need for any recursion, _much_ easier to query children/ascestors, etc., etc.

RockTo
Автор

I thought you were saying that instead writing in recursion (if you have infinite amount of tree height / levels) you would associate one for-loop for each level. What I dont get is why did you still left traverse() in the lowest loop? You will have infinite for loops if you just remove the escape condition.

bokistotel
Автор

At the beginning I got the feeling you were being sarcastic 😅

I think of this concept as *the number of for loops required to solve a problem being dependent on the input* (it appears, for example, in the power set, scanning a number of variable digits or a string). This I take as a sign of recursion being summoned 🧞

fernandoiglesiasg
Автор

might as well use goto TOP: or something lol.

pyrotek