# recursion

## How to perform a recursion in bison?

i am new at flex/bison . I have already written some rules for functions .My problem here is that when i try to write a rule for a main function(in c) it can contains many functions inside . So , i thought that the best way is to write a r…

## Peg solitaire solution program

I am writing an assignment in java for my data structures course. It is to find a solution to a peg solitaire board by using backtracking recursion. I thought I have a good solution in the works through saving the states of the board in …

## Adding numbers in python and in line using function recursion

Hey guys I have a code like this
numStr = str(n)
sum = 0

for i in range(len(num_str)):
sum += int(numStr[])
return sum

I want the answer to be this way.
output: 5 + 4 + 6 = 15
H…

## How to create a multidimensional matrix in python with recursion

Let’s say I have defined a function to generate a list of 6 random integers ranging from 0 to 10
import random
def func():
randomlist = random.sample(range(11), 6)
return randomlist

Run:
func()

Output:
[3, 7, 10, 9, 4, 1]

Now I …

## Python recursive function recurSum(x, y): two positive integers

This is my code:
def recurSum(x, y):
if x <= 1:
return x
return x + recurSum(x – 1)
if y <= 1:
return y

print(recurSum(5, 10))

I would like to write recursive function recurSum(x, y) that takes as an in…

## Quick Sort – Maximum Recursion / Stack Overflow Error

I’m attempting to run a Quick Sort on various arrays of length 5000 (two auto-generated from numpy using distribution) or two pulled from a csv file. I can get the numpy arrays to run the quicksort successfully, but run into a recursion /…

## Error: Abort signal from abort(3) (SIGABRT) when using recursion

Problem Statement:
To construct a binary tree from a given inorder and preorder list.
I was able to write the logic but I get the error Abort signal from abort(3) (SIGABRT) and I ain’t able to find what’s causing this error.
Code:
#include…

## How can I merge this two recursive functions into one?

I want to merge this two functions into one because I want a more readable code, but I can’t finding a solution.
function setTplArray_fn(\$data) {
\$array = [];
if (!is_array(\$data)) {
return htmlspecial…

## JavaScript – Passed string argument become undefined in recursive call

// In this code I am trying to print all paths in a 2D matrix. Where in each step I can move only right or down direction
var n = 3;
var m = 3;
var total = 0;

function mazePath(start,end,n,m,count,output){
if(start==(n-1) &&a…

## Hello I am new to C and I tried how to print a name nth times using recursion but dont know where is did mistake?

I am new to this plz can anyone help me to correct this program.
This is a program to print the entered name nth times.
#include <stdio.h>
char* call(int i, int n,char name){
if (i<=n)
return char name ;
}
int main…

## Why is method returning false despite condition for true being met?

I am confused why it is returning false despite "total" being 1. I am aware the program will run infinitely if total = 1 is not met, but even though it is met, it returns false.
The program is supposed to split the integers of a …

## How to know when a recursive function has stopped calling itself?

Is there any way to know when a recursive function has stopped calling itself?
I have the following scenario:
function print(msg){
console.log(msg);

if(canContinue){
print("Hi there");
}

if(canContinueCase2){

## Passing the int value by reference in recursive function

I am trying to modify the content of lev–>via–>l and co–>via–>co. But I am getting this error:
Error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’

I was able to write my own logic fo…

## Generate consecutive substring from the string using recursion

I am having a string let say ABCD I want to create all the subsets in such a way that they are consecutive like this:
`A` ,`AB`, `ABC`, `ABCD`, `B`, `BC`, `BCD`, `C`, `CD`, `D`

AC, AD, BD etc should not be generated as they are not next …

## JS, how to get a tree grid by recursive

I made a function that take all items, find item without Parent(1 lvl), filter their childs (2 lvl) but I want to write this function recursive, becourse childs have its own childs etc…
I’m newest here and didnt understood all how to mak…

## Function return different values on conditional operator

var recur = (n, m) => {
if (n || m === 1) {
return 1;
} else {
return recur(n – 1, m) + recur(n, m – 1);
}
};

var recur2 = (n, m) => {
return 1 ? n || m === 1 :…

## Recursive method keeps going, but in the opposite direction. Why?

So I’m trying to familiarize myself with recursion and Javascript. So I wrote a simple method to try it out. I’m pretty new to Javascript syntax so I’m not really sure where I’m going wrong. Here is the method.
export const IsEven = (n) =&…

## how do I trace through a recursion to reverse a linked list?

I have some recursive code that reverses linked lists:
#We are dealing with ListNodes.