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
SUMMARY

This discussion centers on understanding recursion in programming, particularly in relation to mathematical concepts like factorials and palindromes. The user seeks clarity on how to approach recursive solutions rather than just the solutions themselves. Key insights include the importance of reducing problems to smaller instances of the same nature and recognizing that recursion can be applied without a visible pattern. Resources such as the Wikipedia article on recursion and specific programming sites like StudyTonight are mentioned for further exploration.

PREREQUISITES
  • Understanding of basic programming concepts, particularly recursion
  • Familiarity with mathematical sequences and their application in programming
  • Knowledge of string manipulation techniques in programming
  • Basic understanding of Java programming language
NEXT STEPS
  • Study the concept of recursion in depth using the Wikipedia article on Recursion in Computer Science
  • Learn how to implement recursive functions for string manipulation, specifically for palindrome checking
  • Explore Java programming resources, focusing on recursion, such as StudyTonight and Programiz
  • Read college-level mathematics books that include sections on recursion and practice problems
USEFUL FOR

This discussion is beneficial for computer science students, software developers, and anyone interested in mastering recursion and its applications in programming, particularly in Java.

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