# Questions tagged [recursion]

Recursion is a kind of function call in which a function calls itself. Such functions are also called recursive functions. Structural recursion is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem.

**0**

votes

**0**answers

11 views

### Execute Javascript recursively WebView Android not working

I am stuck with the problem of WebView, Where I want to execute JavaScript one by one.
What I have to do :
I have one JSON as below, I have to parse that and get "url" and execute. That will be ...

**0**

votes

**0**answers

10 views

### Dynamically show previous/next div with XQuery - recursion?

knowing community,
I want to achieve the following in short: I have a XML-file with listed pizzas inside of it (it is a kind of test file). My page has a select menu from which a user choses one ...

**0**

votes

**2**answers

19 views

### Remove an element from a list in Common Lisp?

I am currently trying to remove any NIL I find from a list (recursively) on all levels. I already know how to remove NIL from the top level of a list, and I thought much of the idea would be the same ...

**1**

vote

**2**answers

45 views

### Finding the shortest path in a maze using recursion?

recently I've been trying to work on some recursive maze code that returns the shortest path in a maze. If there is no path through the maze, then the code would return -1.
For example, for the ...

**0**

votes

**1**answer

24 views

### JS Recursion Maximum call stack size exceeded: difference between 2 functions

I'm working on this example: https://bl.ocks.org/mbostock/1705868
My aim is to add a button which on click will draw a new circle and make it move as the 1st one without reseting its cycle. So I've ...

**0**

votes

**0**answers

48 views

### Simple C factorial program not working properly with big numbers [duplicate]

This is a simple factorial program in C
Large numbers are displaying the wrong thing. Sometimes negative numbers and for factorial of 100 it prints out 0. I'm also long too, how can I fix this?
#...

**0**

votes

**0**answers

24 views

### recursive tree parsing in matlab

I have a map, where my keys are parents and the respective values are the children of said parents. This map can extend to an n-depth if necessary. The map looks like:
K>> obj.hierarchy
ans =
...

**-2**

votes

**1**answer

25 views

### IndexError: string index out of range 2018 python 3

This code basically is mirroring the string you input. I am getting
Type something please: Hey Hello ...

**-1**

votes

**1**answer

46 views

### Recursive issue

I'm coding an algorithm that solves a puzzle, the puzzle is this Image puzzle the puzzle is solved when the green dots are making a triangle between the three circles
I got three arrays, each one ...

**0**

votes

**1**answer

26 views

### Recursive column in sql (postgresql)

I have a equation:
result[n] = least(0, x[n] + result[n-1])
which should produce such a table
x | result
--------------
100 | 0 // least(100+0, 0) = 0
50 | 0 // least(50+0, 0) = 0
-...

**0**

votes

**1**answer

22 views

### How would I find the time complexity of the following recursive algorithm?

Assuming that r is the root of a tree (may be non-binary), c is a child of r, and each node contains an integer.
Algorithm findMax(r)
if r = null return null
int maxValue = r.value
if r.isLeaf return ...

**-2**

votes

**0**answers

16 views

### Create a nested dictionary from a spark data-frame

I want to create a nested dictionary from a spark data frame.( So far I was using the pandas data-frame, and i found a very useful recursive function to achieve my objective).
def recur_dictify(frame)...

**0**

votes

**2**answers

65 views

### Haskell recursion in IO action

Still a beginner that can't figure out a recursive loop in an IO action. Assume:
fMinInspect :: Int
fMinInspect = 1
fMaxInspect :: Int
fMaxInspect = 12
-- fNoInspectPerHour :: IO ()
fNoInspectPerHour ...

**0**

votes

**1**answer

77 views

### Why using loops in recursion produce an unexpected results?

I have the following function.
int n,cnt,i,j;
int a[100];
void can(int x,int c){
if (x == 0){
for (i = 0; i < c; i++){
cout << a[i];
} cout<<endl;
}
...

**-1**

votes

**6**answers

61 views

### Explain Python Recursion like I'm 5 [duplicate]

So I found this example of recursion in Python on W3 Schools, but am having trouble wrapping my head around it.
def tri_recursion(k):
if(k>0):
result = k+tri_recursion(k-1)
print(result)
...

**1**

vote

**1**answer

31 views

### How access a specific position in racket list

I am having problems in getting the position of the list I want.
I am not sure is what to use to be able to get the value from the asked position.
If it was python I could repeat (fist( rest n) as ...

**1**

vote

**1**answer

38 views

### Recursive function to traverse directories using fork() running too many times

I am trying to get a better understanding of the concept of forking a process by traversing a directory in C.
My function is not working how I expect it to: some of my directories and files are being ...

**0**

votes

**1**answer

41 views

### Is my recursion solution to this problems correct?

I need to solve this by recursion, here is what they ask to do:
Write a recursion function that takes a positive number and returning the sum(+,-) of its digits from right to left, like this way(for ...

**-1**

votes

**1**answer

76 views

### Swapping elements of vector if less than a value k recursively

Given the function below, recursively move all the values to the left side that are less or equal to the value k. No helper functions are allowed.
vector<int> shift(const vector<int>& ...

**3**

votes

**3**answers

42 views

### Recursively multiply all values in an array Python

I've had a look through the forums and can't find anything to do with multiplying all elements in an array recursively.
I've created the following code that almost does what I want. The goal is to ...

**-5**

votes

**1**answer

66 views

### Haskell, returning a char nth times [on hold]

I am trying to make a function in haskell using recursion that takes two arguments.
The function takes a char and an integer and will return the char n th times depending on the integer.
Thanks in ...

**0**

votes

**0**answers

57 views

### Interesting algorithm task - Directions [duplicate]

Some time ago I've encountered an interesting algorithm task, and I'm having quite a big difficulties solving it.
The task
You are given two variables, L and R which correspond to the directions ...

**1**

vote

**2**answers

62 views

### SQL Server Results all possible ordering

I am new to this forum and seeking help on following issue.
I am looking to get all possible ordering from a result set.
e.g
Column1
-------
val1
val2
val3
Expected Result
RowNumCoumn Column1
---...

**0**

votes

**0**answers

42 views

### Recursion of an hexapawn solver

Good morning every one,
I'd like to do a recursive function that takes as parameter a configuration of the game héxapawn and returns its evaluation.
this function recursively evaluates all successors ...

**0**

votes

**1**answer

30 views

### PHP Recursion doesn't seem to be traversing all avenues

This program is supposed to find all the possible ways down through a maze, and save the farthest distance down it got in a global variable. Instead it only travels one path and then ends? I'm ...

**0**

votes

**0**answers

22 views

### delete node in BST python

class Node:
def __init__(self,data):
self.data = data
self.left = None
self.right = None
self.count = 1
class BST:
def __init__(self):
self.root = None
...

**-2**

votes

**0**answers

11 views

### Exception “dispatchUncaughtException” triggered when making recursive call

Estou tentando fazer uma chamada recursiva e está dando este erro, alguém sabe me explicar o que é exatamente? Fiz umas pesquisas no Google mas não entendi bem.
Esta é a exceção:
/**
* Dispatch ...

**1**

vote

**1**answer

45 views

### Why is the space complexity of a recursive method that creates a binary tree of calls O(h)?

Given this method:
int f(int n) {
if (n <= 0) {
return 1;
}
return f(n - 1) + f(n - 1);
}
Creates a stack call/binary tree like so:
n
/ \
n-1 n-1
/ \ / \
n-2 n-...

**0**

votes

**0**answers

43 views

### Find simple cycles with recursion in a directed graph. C

I have a directed graph and I am trying to find all simple circles of a graph node in it.
My graph looks something like this
Each g_node, which represents a username, has a t_nodes list, which ...

**-4**

votes

**2**answers

40 views

### Recursion Issue

So I am attempting to have a simple recursion method that prints the digits of a number backwards. I hard-coded the length-1 of the digit in, so if I had a four digit number, length would be three. ...

**0**

votes

**1**answer

23 views

### f# function to calculate n! faculty

I am trying to write a function (fac : n:int -> int), that calculate N! faculty using recursion. But i got something very wrong. hope you can help
let rec factorial (fac : int -> int) =
if ...

**2**

votes

**3**answers

37 views

### How to export local folder structure with nodeJS?

Reading directories recursivly is not the problem. There are many good libraries for it, for instance recursive-readdir.
I am searching for a solution to extract only the folder structure without any ...

**0**

votes

**1**answer

66 views

### Why is there wrong output after declare variable in loop? - (WrongQuestion: How to use Promises in a recursive method to declare a variable?)

This question is based on this one:
How do i add a summed list in a recursive method?
This time I wanted to calculate the average of the resultObject. Therefore I created a resultlist with all ...

**2**

votes

**1**answer

37 views

### C - Recursive algorithm calculating determinant of a 2D matrix

I want to recursively calculate the determinant of a 2D matrix, according to the definition of cofactors and their use in calculating the determinant. My code is:
double **supr_mat(int size, double ...

**0**

votes

**1**answer

52 views

### Experiencing java.lang.StackOverflowError Exception ,When calling method

I have written a code which parses the JSON body in map it works fine but when JSONArray is detected it throws exception after some iterations.
import com.google.gson.JsonArray;
import com.google....

**2**

votes

**1**answer

30 views

### Series calculation based on shifted values / recursive algorithm

I have the following:
df['PositionLong'] = 0
df['PositionLong'] = np.where(df['Alpha'] == 1, 1, (np.where(np.logical_and(df['PositionLong'].shift(1) == 1, df['Bravo'] == 1), 1, 0)))
This lines ...

**0**

votes

**3**answers

95 views

### How to write unzip using foldr in scheme?

This is the code for unzip function coded in Scheme
(define (unzip lst)
(define (firsts lst)
(if (null? lst)
'()
(cons (caar lst)
(firsts (cdr lst)))))
(define (...

**0**

votes

**0**answers

71 views

### MIPS Assembly recursive binary search tree not setting left and right child nodes

I implemented a recursive binary search tree and am having a hard time adding in nodes once I set the root. Conceptually, I know what I need to do and drew out a quick example (I apologize if the ...

**1**

vote

**2**answers

43 views

### Recursive program in RISC-V assembly

I am trying to create a recursive program in RISC-V but I can't get it to get me the right result. It looks like it is calling itself only two times max, but I tried running it on paper and everything ...

**1**

vote

**1**answer

33 views

### Trouble returning bool from recursive function

I'm working on a homework problem in which we have to write an algorithm that can determine if a graph is bipartite or not. My python solution works, but right now it throws an exception if the graph ...

**-2**

votes

**0**answers

36 views

### recursive function to see if 2 strings have the same number of occurrences of a character [on hold]

I am trying to write a function that will take in 2 strings and a character as parameter, and search both of these strings if they have the same number of occurrences of the character parameter that ...

**0**

votes

**0**answers

24 views

### SQLAlchemy RecursionError: maximum recursion depth exceeded while calling a Python object

I currently am stumped as to why I'm gettign the recursion error from the title with the code down below. This error only comes up if either of the for loops are hit (under if ops and if compliance) ...

**0**

votes

**6**answers

58 views

### How can I combine elements of an array that are linear?

My data looks like:
[ [ '0s', '0.200s' ],
[ '0.200s', '0.600s' ],
[ '1.600s', '2.500s' ],
[ '3.500s', '3.900s' ],
[ '3.900s', '4.400s' ],
[ '4.400s', '4.600s' ],
[ '4.600s', '4.700s' ],
...

**2**

votes

**2**answers

50 views

### Iterating from the end to the beginning of a single-linked list without reversing it

Say I have a single-linked list with words collected from a file from which I want to be able to print such words both from the beginning to the end and from the end to the beginning. The execution of ...

**1**

vote

**1**answer

31 views

### Best way to build a hierarchical tree from array having root and child conditions

I've tried to build a tree from results of dataset as array of objects, but IE have bad feeling with it.
The problem it's the timing.
I have to process data like this to build tree:
var DataSet = [{
...

**0**

votes

**1**answer

65 views

### Quick sort recursive function in C - doesn't work with big number of elements

Has this function been written correctly?
It seems that something is wrong when I try to run the function with a large number of elements in the array (eg 1000).
Then its appears to stop.
int ...

**0**

votes

**1**answer

20 views

### Stack lists into nested list like a matryoshka in python

I have some "big" lists, that fit into some other lists of the same list of the "big" lists, and I would like to map the sublists into one another, to get the one containing all the others. Its sorted ...

**-1**

votes

**1**answer

40 views

### Function doesn't Break [on hold]

I am trying to break out or restart a function in python 2. Putting a return statement should stop all execution. Same goes for restarting the function.
def function():
...
if len(lst) == 1:
...

**2**

votes

**1**answer

55 views

### Recursive function and this D3.JS

I have an array of points with point={x,y,nextPoint}. The aim is to draw a line between each point and move a circle on it. The nextPoint of the last point in the array is null.
I was able to move a ...

**1**

vote

**1**answer

62 views

### how to access variable values of previous call from current call in recursion

I am making a recursive function to insert value in a btree. Before moving to the next node, I save the address of that node(pds_parent) so that I always have a pointer pointing to the parent.
But ...