How do I think about recursion in programming?

  • Context: Comp Sci 
  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Programming Recursion
Click For Summary

Discussion Overview

The discussion revolves around understanding recursion in programming, particularly in relation to mathematical concepts and specific problems like checking for palindromes. Participants explore how to approach recursive solutions and seek resources for further learning.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant discusses the idea of recursion using examples like factorials and sums, expressing a desire to understand the approach to finding palindromes rather than just the solution.
  • Another participant suggests that if the two ends of a string are equal, they can be removed and the function can be called with the smaller string.
  • It is noted by a participant that recognizing a pattern is not necessary for using recursion, as long as the recursive call addresses a smaller problem of the same type.
  • Several participants inquire about college or university-level math books that might contain excerpts on recursive functions and practice problems.
  • One participant mentions that recursion in programming relates to mathematical sequences but suggests that computing problems may not be found in traditional math textbooks.
  • A participant shares a link to a resource for checking palindromes using recursion, emphasizing the importance of simplifying the problem to a smaller string.
  • There are comments regarding the usefulness of certain online resources for learning programming languages like JavaScript, with differing opinions on their effectiveness.

Areas of Agreement / Disagreement

Participants express varying opinions on the necessity of recognizing patterns in recursion and the effectiveness of different learning resources. There is no consensus on the best approach to understanding recursion or the most suitable educational materials.

Contextual Notes

Some participants express uncertainty about the specific recursive solution for palindromes and seek clarity on the reasoning behind it. There is also a lack of consensus on the quality of online resources for learning programming.

shivajikobardan
Messages
637
Reaction score
54
Homework Statement
thinking about recursion in programming for palindrome checker
Relevant Equations
none
I got the idea for problems like factorials or finding sum from 1 to n, where there's a pattern visible. Like this:
n7yRPLDzxUujdzMyPic6CcpXm0o6GEvJZ1lmZzfTfbkhaa608Q.png

Source:https://99x.io/blog/recursion-is-not-hard-here-is-the-right-way-to-think

I got it for things like addition, subtraction, division, multiplication of two numbers as well.

eg: a+b

=a+b-1+1

=SUM(a+1,b-1)

Now, I am wondering how it'll be for finding a palindrome of a number? I've a solution but I'm not understanding how we came towards it. I'm looking for how to come towards a solution than a solution itself.

A number is palindrome if it's same as it's reversed. eg: REFER, RADAR, NOON etc are palindrome strings.

I'm unable to grasp a pattern here. Also, please share some books based on mathematics(Not full books but part of book on recursion) that have exercises of recursive functions. I think that'd help greatly with recursion.
 
Physics news on Phys.org
If the two ends are equal then remove them and call the function with the smaller string.
 
  • Like
Likes   Reactions: scottdave
You don't necessarily have to see a pattern to use recursion. As long as the recursive call is applied to a smaller problem of the same nature, you can use recursion to repetitively reduce it to an elementary problem.
 
which college/university level math book could contain excerpts about recursive functions and practice problems?
 
shivajikobardan said:
which college/university level math book could contain excerpts about recursive functions and practice problems?
Recursion in programming is associated with the mathematical concept of sequences but you won't find computing problems of this kind in a maths text book.

The Wikipedia article on this is quite a good start point https://en.wikipedia.org/wiki/Recursion_(computer_science)
 
  • Like
Likes   Reactions: scottdave and FactChecker
pbuk said:
Recursion in programming is associated with the mathematical concept of sequences but you won't find computing problems of this kind in a maths text book.

The Wikipedia article on this is quite a good start point https://en.wikipedia.org/wiki/Recursion_(computer_science)
that's like entire dsa(recursion related) in 1 post.
 
shivajikobardan said:
Now, I am wondering how it'll be for finding a palindrome of a number? I've a solution but I'm not understanding how we came towards it. I'm looking for how to come towards a solution than a solution itself.
It might help if you show the solution that you have questions about.
 
In that link, this is the critical part that hints at a solution using regression:
7. If the first and last characters of the string are the same then carry out the same for substring with the first and last character removed.

That means that the problem can be simplified to a smaller string to check for being a palindrome. Doing that over and over until the string is so short that it can be checked trivially.
 
  • #10
I had not heard of StudyTonight site before. Can anybody comment on it for learning (for example JavaScript)?
 
  • #11
scottdave said:
Can anybody comment on it for learning (for example JavaScript)?
It seems completely useless for learning JavaScript. Stick to well known resources like Programiz.
 
  • #12
pbuk said:
It seems completely useless for learning JavaScript. Stick to well known resources like Programiz.
Thanks
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K