What Is Recursion in Programming?

What Is Recursion in Programming?

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI

Оглавление (1 сегментов)

Segment 1 (00:00 - 01:00)

Recursion is simply a way to break down a problem into smaller pieces. And sort of technically speaking, it is when a function calls itself. More practically speaking though, what exactly is recursion? Imagine we have these playing cards and we want to count the playing cards. There's an iterative approach where we simply say 1 2 3 4. We have four cards. But then there's the recursive approach. Bear with me. This is going to seem like I am greatly over complicating the process of counting to four, but there is a purpose here. So, another way to count these cards is to say, well, I know I have one card and then I I've got all these. We'll call these the rest. So, I've got one plus the rest. Now, how do I count the rest? How do I know what that is? Well, I know there's one card and then again, there's the rest. So, I've got this one plus the rest. But how do I count these? Well, I can take one card and say I have one plus the rest. And now this time, I just have one card. There's no rest. Then we can go back up that call stack as we call it. So we can go to the previous call where we said we had one plus the rest. And that rest we know is one. So we have 1 plus 1 that's two. And then this one we said we had one plus the rest which we know the rest is now two. So that's 1 plus 2 that's three. And then we had originally 1 plus the rest. And the rest here we know now is three. So we have 1 + 3 which is four. And that tells us that we have four cards. And this is essentially what recursion is. It's solving a very small part of the problem and then recursively saying, "Okay, I'll go solve the rest of it later. " And then eventually we go all the way back up to the beginning and we have a completed solution.

Другие видео автора — Conner Ardman

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник