How does recursion really works in computer science?

193 views

How does recursion really works in computer science?

In: 0

5 Answers

Anonymous 0 Comments

Imagine you have a man that is neither smart nor dumb, he will simply follow instructions to the letter, this is a computer.

You hand him a stick and tell him: “Break this stick in half, now give me the sticks” he takes the stick, breaks it in half, and gives it back to you. This is an example of a non-recursive function since you give him precise instructions on what to do and a end result.

You hand him a stick and tell him: “Whenever you have a stick, break it in half” he takes the stick, breaks it in half, looks down and sees he now has 2 sticks, which he each breaks in half, then he looks down and sees he now has 4 sticks… This will go on forever until he has a stick so small he can no longer break it in half. Then he comes to you to tell you he couldn’t do his job. This is an example of a recursive function.

Recursion can be an amazing tool to use but is impossible to fully predict in more complex instructions, it is any instruction that will repeat itself until certain conditions are met (or not) you can use it to calculate absurdly large numbers (A good example is Pi) but there is never really a guarantee that it will finish what it was told to do without causing problems (errors)

You are viewing 1 out of 5 answers, click here to view all answers.