All Questions
24 questions
0
votes
1
answer
84
views
How can these specific functions be convereted from using recursion to using iteration?
I've been working on porting a library from C to CUDA. Two functions that I need to port make use of recursion, which CUDA doesn't seem to be playing nicely with. I therefore want to convert these ...
0
votes
1
answer
25
views
Expected output not returned for spiral coordinate computation functions (iterative and recursive)
I'm trying to compute the x-coordinate of the nth arm of a spiral using both an iterative and a recursive function. However, I am not getting the expected output from the code. I have written two ...
2
votes
1
answer
56
views
How to convert a recursion with multiple recursive calls into an iteration? I already know how to do it when there is only one recursive call
Here is how I would convert a recursive function that only has one recursive call (I'll use JavaScript)
function f(n){
if(n>0){
f(n-1);
doStuff(n); //this could be anything
}...
1
vote
2
answers
232
views
How to improve recursive function in C?
i have a program with various recursive functions.
I now need to optimize the code to run the program faster: i checked with profiler and, a part from the biggest function with lots of checks, i have ...
1
vote
2
answers
328
views
Write a function that for a given a non-negative int n, returns the count of the occurrences of 9 as a digit
I can't solve this problem and I've been trying to wrap my head around it for a couple of days now. Here's the full text of the problem:
Write a function that for a given a non-negative int n, ...
-1
votes
2
answers
431
views
Convert c++ function from recursive to iterations with stack
I'm trying to convert this function from recursive to iterations with stack but I can't figure out how and I keep failing
int F(int n)
{
if (n <= 1) return 1;
int a = n + F(n - 1);
cout ...
0
votes
4
answers
68
views
Creating an Iterative - Javascipt
I have a recursive function below and I was just wondering how can I create an iterative (i.e. loops without recursion) for the same thing. I would really appreciate any help or suggestions thank you!
...
1
vote
2
answers
42
views
Why is my basic recursion looping infinitely?
let data = [1, 2, 3]
let sorted = []
let push = function(i) {
while(i<data.length) {
sorted.push(data[i])
push(i + 1)
}
}
push(0)
Hey guys,
I am writing some basic recursion and it ...
1
vote
2
answers
2k
views
How to write a function for Hermite polynomials?
For 2 numbers x and n entered by the user, my code needs to find Hn(x) defined recursively by the following formulas:
I am trying to implement a recursive version and and iterative version of that ...
0
votes
3
answers
270
views
transforming recursive function to iterative in C
I need to an iterative function but I can only think about It as recursive
int f(int m,int n)
{
if (n == 0)
return m;
if (m == 0)
return n;
return f(m+1, n-1) + f(m, n-1) +...
3
votes
5
answers
37k
views
Formal and actual parameters in a function in python [duplicate]
I'm kind of confused on how to identify the formal and actual parameters in a recursive function. For example in this block of code for getting the factorial of a number:
def factorial(n):
if n ==...
1
vote
1
answer
172
views
How to convert this recursive function to a iterative one? (var_dump in javascript)
I'm new here and I'm trying to convert a recursive function to iterative.
I have been reading about the subject for some days and I have found some good sites that gave me ideas to try. But I couldn'...
0
votes
1
answer
23
views
Recursive function to iterative
The following function is given:
T(n, 0) = n, n >= 0,
T(0, k) = k, k >= 0,
T(n, k) = T(n - 1, k - 1) + T(n, k - 1) + 1, n > 0 and k > 0
The thing I'm trying to achieve is to ...
2
votes
2
answers
3k
views
Counting Iterations in recursion
I'm trying to keep track of iterations through this recursion, but 'iter' always returns 1.
def compute_root(poly, x_0, epsilon): ##Using Newton's method
iter = 0
try:
if abs(evalpoly(...
2
votes
1
answer
1k
views
Who to talk to about non recursive Ackermann function?
I have written a non recursive solution to the Ackermann function, it seems to work perfectly and work faster than the common recursive solution. So I am confused as to why it is a non primitive ...