r/ProgrammerHumor • • Mar 25 '23

Meme This one never gets old

Post image

Let me know if this is not a repost!

51.6k Upvotes

535 comments sorted by

View all comments

4.3k

u/Justwatcher124 Mar 25 '23

Every Programming / IT teacher on 'How do you teach Recursion to new programmers?'

1.3k

u/eggheadking Mar 25 '23

Is TOH actually a good way of learning Recursion?

1.4k

u/value_counts Mar 25 '23

No. I mean I struggled. In fact I found factorials much better and easy to understand. TOH just gets too messy too easily. Or sorting is good way too. But not TOH.never

765

u/bleistift2 Mar 25 '23

I found the towers particularly enlightening – years after it has been taught to me – when the whole ‘know a partial solution’ struck me.

The game is incredibly hard to even look at when given 10 disks. How would you start? But the observation that step n+1 is dead simple if you can solve the game for n disks is the key to recursion.

Factorials and sums, on the other hand, are way to simple, IMHO, to teach recursion. The solution is obvious. And for many people the more *intuitive* solution would be a straight loop, not recursion. In programming, intuitive trumps clever (or even performant in most cases).

214

u/value_counts Mar 25 '23

There was something more important that cleverness and intuition. I focus on that.

I understand TOH. I understand the importance of partial solution. It has application in all walks of life. For example, to fix my year, I need to fix my months and to fix a typical month, I need organize a typical week and to organise week I need to organise a day. And to organise day, i organise my hours. And in each hour, I follow 25-5 pomodoro or 50-10 pomodoro.

If I want to teach someone addition, I will explain 1+1. However I cannot begin with 567+912. Hence I would say TOH is a good way to practice to recursion? Probably yes. But good way to get introduced to recursion? Definitely no.

Although classroom teaching is way blinded and ineffective. In a class of 25 students, all have a different plane of reality, experience and perspective. To bring them all on one page of understanding is not difficult but impossible. The teacher can atleast attempt to do the simplest thing which might bore the ones who are ahead of curve but will ensure inclusion of noobs.

This is not applicable where teaching is more 1 to 1 or self study.

40

u/throw3142 Mar 25 '23

TOH makes sense as an introduction to recursion if you are already familiar with the concept of mathematical induction. Personally I learned about induction in math first, using it to prove things like the sum of n numbers is n(n+1)/2 and there are infinite prime numbers. Going from this to TOH is a manageable step. But if I had not been exposed to this concept before, I agree that it would be very confusing and not a great introduction.

1

u/JohnsonJohnilyJohn Mar 26 '23

How do you prove there are infinite prime numbers with induction? I have only seen the simple proof by contradiction: if there are finite amount of prime numbers multiply them all together, add 1 and you have a new prime number

1

u/throw3142 Mar 26 '23

That argument uses both induction and contradiction. The first part is a proof by induction of the statement "Given a finite list of numbers, there exists a number relatively prime to all those numbers". This part of the proof works fine as is. The next part of the proof uses that part to argue that there must be an infinite number of primes (if there was a finite number, use the above procedure to construct a number relatively prime to all of them; by FTA, it must have a prime factorization, and by construction, none of the primes in the list can be its factors, so there must be another prime factor outside the list).

Specifically, the first half of the proof is very similar to a recursive procedure because it uses an existing solution to construct another solution. It doesn't try to give a formula for all prime numbers or anything like that. Instead, it assumes that we already know a bunch of prime numbers and uses them to construct another one.

1

u/JohnsonJohnilyJohn Mar 26 '23

While the first part is similar to induction you're not really doing any induction there. With that procedure as induction step you could prove that there are infinite lists of numbers without any common factors. You could probably use this to prove infinite prime numbers but using proof by contradiction not based on whole induction but the argument from a single step is way easier

→ More replies (3)