Hi , i have problems to learn recurtion

  • Thread starter transgalactic
  • Start date
  • Tags
    Hi
In summary, the conversation revolves around understanding subsets and recursion in the context of Java programming. The example used is from set theory, and it is suggested to use recursion on the empty set to find subsets. The function f(S{}) should be able to recognize the empty set and find subsets from it, allowing for a recursive call on each subset.
  • #1
transgalactic
1,395
0
i have this question which are femiliar to the
codes which we learned in class like subsets

but when i try to looks on the subsets code
i can't see the logic of it

how do i understand it??
 
Technology news on Phys.org
  • #2
Langauge what, that is in ?
 
  • #3
java
 
  • #4
Sounds like your are learning recursion and the example you are using is taken from set theory, namely sets and subsets.

Hint: let your recursion terminate on the empty set.

if your function
f(S{})
works on sets, S{},
recognises the empty set {}, and
can find subsets from S{}, then
for every subset Si{} in S{} you can
call f(Si{}).
 

What is recursion?

Recursion is a programming technique where a function calls itself until a base case is reached. This allows for a problem to be broken down into smaller subproblems, leading to a more efficient and elegant solution.

Why is recursion important in programming?

Recursion allows for complex problems to be solved in a simpler and more concise manner. It also helps with code readability and maintainability, as recursive functions can be easily reused in different parts of a program.

What are some common challenges with learning recursion?

One of the main challenges with learning recursion is understanding the base case and how it leads to the termination of the recursive function. Another challenge is visualizing the recursive process and understanding how data is being passed through each recursive call.

What are some common mistakes when implementing recursion?

Some common mistakes include not having a proper base case, leading to an infinite loop, and not properly updating the parameters passed into the recursive function, leading to incorrect results. Another mistake is not considering the space complexity, as recursive functions can use up a lot of memory.

How can I improve my understanding of recursion?

Practice is key when it comes to understanding recursion. It is important to start with simple examples and gradually move on to more complex problems. Additionally, studying the recursive process and understanding how data is being passed through each recursive call can help improve understanding.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
8
Views
817
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
1
Views
444
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
5
Views
866
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
4
Views
842
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top