Difficult recursion problem in C

  • Thread starter dan.b
  • Start date
  • Tags
    Recursion
In summary, The conversation discusses the need for a recursive function that fills a character array with all possible subsets of a given size from a given word, while not using any loops, pointers, or static variables. The use of a depth-first recursion technique is suggested and an example is provided, along with a reminder to consider base cases.
  • #1
dan.b
2
0
Hi, everybody.
I really need your help with this question that giving me no sleep at nights. :( no loops and no pointers, and No STATIC can be used.
Write a recursive function that fills the given character
array with all possible given-size subsets of characters in
given word, separated by commas

does anyone have an idea?
 
Last edited:
Technology news on Phys.org
  • #2
No pointers? The function takes two pointers as arguments!

The order of the desired output strongly indicates you should be looking at a depth first recursion technique.
 
  • #3
it means no using *types, calling to r as an address in the array is fine.
what is first recursion technique can you add an exmple?
 
  • #4
The subsets of size m of the numbers 1,2,...n are:
1, added at the beginning of the subsets of size m-1 of the numbers 2,3,...,n
followed by the subsets of size m of 2,...,n
This doesn't consider the base cases--base cases are when m=0, or when the range of numbers considered is empty.
 
Last edited:
  • #5
That's a bit too much help, mXSCNT.
 
  • #6
Alright, I'll delete the second part.
 

Related to Difficult recursion problem in C

1. What is a difficult recursion problem in C?

A difficult recursion problem in C is a programming challenge that involves using a function to call itself repeatedly until a base case is reached. This can be challenging because it requires a deep understanding of how recursion works and how to properly structure the function to avoid infinite loops.

2. Why is recursion considered difficult in C?

Recursion can be difficult in C because of its low-level nature and lack of built-in support for data structures like stacks. This means that the programmer must carefully manage memory and control the flow of the recursive function to avoid errors and inefficiency.

3. How can I approach solving a difficult recursion problem in C?

To solve a difficult recursion problem in C, it is important to first understand the problem and its requirements. Then, you can break down the problem into smaller subproblems and identify a base case that will stop the recursive calls. Finally, you can use careful programming techniques, such as passing parameters and using temporary variables, to manage the recursion and ensure that it terminates correctly.

4. What are some common mistakes when using recursion in C?

Some common mistakes when using recursion in C include forgetting to define a base case, not properly handling memory management, and accidentally creating infinite loops. It is also important to pay attention to the order of operations and the use of temporary variables to avoid errors.

5. Are there any resources available to help with difficult recursion problems in C?

Yes, there are many online resources, tutorials, and practice problems available to help with difficult recursion problems in C. Additionally, textbooks and programming forums can be useful for finding tips and solutions from experienced programmers. It is also helpful to practice and become familiar with common recursion techniques and patterns.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
20
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
7
Views
5K
  • Programming and Computer Science
Replies
8
Views
8K
  • Programming and Computer Science
Replies
31
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Programming and Computer Science
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Sci-Fi Writing and World Building
2
Replies
48
Views
5K
Back
Top