Most voted "recursion" questions
In computer science, recursion is a method of solving problems in which the solution is given by an algorithm that refers to itself. A classic example is the factorial calculation of a number.
Learn more…240 questions
Sort by count of
-
0
votes2
answers246
viewsCreate a dynamic object recursively
I’m getting my ass kicked to make a very simple stop: assemble an object in Javascript by an array (exploded string). I need to mount an object dynamically (recursive) like this: { caneta: { cor: {…
-
0
votes0
answers78
viewsProblem with algorithm in C
Good people , is the following , I am developing a project that aims to find a word in a soup of letters , the rules are as follows: The letter can be found at any position ( East, North , South ,…
-
0
votes1
answer64
viewsExit a method call cycle
Let’s imagine the following situation: A company has the policy of donating 3% of its profit to social projects, and this amount donated should come as an expense to the company in the period.…
-
0
votes1
answer515
viewsRecursive function that returns the sum of the divisors of a number
As an exercise I had to create a recursive function that returns the sum of the divisors of a number. I made the following code, but is giving maximum recursion error: def somadiv(n, i = 1, s= 0):…
-
0
votes0
answers44
viewsStackoverflowerror when trying to call recursive method
I’m developing an image editor Paint, and I can’t do the paint bucket method, the idea is: (example) I have an 8x8 matrix and the possible values in this example are "-", "X" or "O" 0 1 2 3 4 5 6 7…
-
0
votes1
answer91
viewsCreate a recursive function to accuse the occurrence of an element in a matrix
I have some problems creating a recursive function that accuses the occurrence of a requested element. So far, this is what I’ve been able to do (perhaps I’ve made some mistake with pointer…
-
0
votes1
answer143
viewsRecursive function returning Undefined in Javascript with Node
The recursive function below stops running when it arrives at "if (Sorted) " and the condition is true, as it should. Only it doesn’t matter what I put in to return, she doesn’t return. If I do…
-
0
votes0
answers54
viewsHow to solve segmentation failure (recorded core image) in recursion?
I’m having trouble with this part of my show. I have to do a function with the Bron-Kerbosch algorithm, but it is giving the following error: segmentation failure (image of the recorded core) and I…
-
0
votes0
answers46
viewsRecursion Return
I’m trying to create an application where I put source, destination and cost data into an array and the user must enter the source and destination so that the system can then scan that array and…
-
0
votes1
answer70
viewsImplicit recursion when assigning the return of a function to a variable?
Speak guys, I’m starting studies in Python and I came across a behavior a little strange for me. It’s this: I have a file test py. which contains some functions. In another file, exempl1.py imported…
-
0
votes1
answer334
viewsHow to do a file search using Python
Problem: Implement the function search(), which accepts as input the name of a file and the path of a folder, to search for the file in the folder and in any folder contained therein, directly or…
-
0
votes1
answer169
viewssoma_ll function that receives a list of lists and returns the sum of all numbers
def soma_ll(lista): return lista[0] + soma_ll(lista[1:]) Why doesn’t my test run? def test_600_soma_ll(self): self.assertEqual(soma_ll([1,2,3]),6) self.assertEqual(soma_ll([1,2,3,4]),10)…
-
0
votes1
answer149
viewsRecursive function JS
I’m studying a little recursive function and I came across an exercise that’s taking my sleep, because it’s a basic exercise and I don’t understand the way out. Basically the book asks to create a…
-
0
votes1
answer69
viewsHow to use recursiveness to iterate in array
I’m looking to implement a recursive function that traverses an array and returns the elements (an alternative to the loop for educational purposes, only). I did it this way, but he returns to me…
-
0
votes1
answer76
viewsHelp with recursive function in Python
I am a beginner with a lot of difficulty in understanding the recursive function, I know it is a function that calls itself, but I can not make it work happily, in the exercise practiced in class,…
-
0
votes2
answers59
viewsSerialize to different objects in C#
How I have to create my class in C# to be able to serialize this json that comes in a request for my API? [{ "name": "campo_normal_1", "value": "valor do campo 1 normal" }, { "name":…
-
0
votes0
answers28
viewsRecursive List with depth count
I created a code to organize a recursive list of categories to print as follows: category 1 -- category 1.1 category 2 -- category 2.2 --- category 2.2.1 json file of data : const data = {…
-
0
votes1
answer24
viewsJava function does not return the correct value
I’m not getting the desired value from the recursive function below. I have tried putting a System.out.println to monitor the values of the cycleLength and n variables and the result was that for…
-
0
votes1
answer97
viewsError when calculating tree height Trie in C
I need to implement a code that calculates the height of a tree Trie in the C language. To struct of knot is the following: struct trie_cel { char tipo; // 'I': interno / 'P': palavra struct…
-
0
votes1
answer47
viewsJavascript recursiveness
Save, I started reading the book "Javascript Eloquent" and in the chapter on higher order functions I came across the following example of a code that calculates the genes that an individual…
-
0
votes2
answers82
viewsDoubt with recursive function in C
Good night, you guys! I am performing an activity whose goal is to use a recursive function to perform a whole division only through successive subtractions. I made a while loop and only it (which I…
-
-1
votes1
answer1092
viewsRecursive Fibonacci sequence
I’m studying Java and I need to do a recursive Fibonacci program, but I have no idea how to do that. Please, if you know, help me. Here’s an inductive code: public static void main(String[] args) {…
-
-1
votes2
answers92
viewsReturn the Fibonnaci elements from the term passed to the first
I have made the return of some specific elements already, but I am trying to return up to the first. In the code below I returned a certain element, as I create from now until the first, until the…
-
-1
votes3
answers259
viewsProblem with recursive function, 2 parameters
I’m trying to write this code using recursiveness: #include <stdio.h> #include <stdlib.h> #include <locale.h> int potencia(int i, int j) { return (j > 0) ? 1 : (potencia(i , j)i…
-
-1
votes1
answer919
viewsPython recursive function that returns the largest and smallest value within a list
Could someone help me with a light? I can do the recursive function to find the lowest value in a list, and the highest value separately. But a function returning the two together I cannot. The…
-
-1
votes1
answer787
viewsRECURSION IN C - COUNT EVEN NUMBERS OF A VECTOR
#include <stdio.h> #define N 6 int verificaPar (int v[], int n, int qtd, int indice); // protótipo int main() { int vetor[N] = {13, 6, 8, 3, 4, 9}; // vetor igual do exercicio int resultado ;…
-
-1
votes1
answer94
viewsHow to pass values up in a tree in javascript
Hello, I’m doing an exercise that consists in making an algorithm that plays the game of old, so far I managed to generate all the game paths and detect which lead to victory or defeat and organizes…
-
-1
votes1
answer76
viewsReturning the inverse of a recursive sequence of numbers in Python
Well, it follows my code that aims to find the inverse of a list in python through recursive def inverso(n, seq): if len(seq) == 0: return else: ultimo_valor = seq[n-1] print(ultimo_valor, end=' ')…
-
-1
votes2
answers109
viewsWhat does the computer do with 2 distinct values that need to be returned and are in the same memory scope?
I have this code with this single function, it performs the product between 'a' and 'b' that it receives from the "main" function. I would like to know how the function contained in this code deals…
-
-1
votes0
answers22
viewsinvert list recursively
#include <iostream> using namespace std; template <class W> struct nodo { W key; nodo<W> *next; nodo(W x) { key = x; next = 0; } }; template <class T> class lsord { private:…
-
-2
votes2
answers108
viewsConvert add and remove functions in tree to recursive
I’m having trouble converting two tree functions into C recursive form. int insere_arvore(ArvBin* raiz, int valor){ if(raiz == NULL) return 0; NO* novo; novo = (NO*) malloc(sizeof(NO)); if(novo ==…
-
-2
votes1
answer52
viewsRuntime recursive function
How I calculate the running time of a recursive function? public void ordenar(int vetor[],int i,int f){ boolean aux2=true; int inicio=i,fim=f; while(i<f){ if(vetor[i]>vetor[f]){ int…
-
-2
votes0
answers28
viewsRecursive function to return largest element in a list
Recursive function that receives a lista and return the highest value from that list. def maior(lista): maior=0 if len(lista)==0: return lista elif len(lista)==1: return lista else: for i in lista:…
-
-2
votes1
answer339
viewsThe difference between the value of a maximum and minimum element of a vector recursively
I made that code : int difrecursivo(int *vetor,int tam){ if(tam == 1) return vetor[0]; else{ int max = vetor[0]; if(max < vetor[tam-1]) max = vetor[tam-1]; int min = vetor[0]; if(min >…
-
-2
votes2
answers155
viewsHow can I do this recursive function
Implement a recursive file_recursive function it receives a list and a number and returns the list, except every time the number appears For example filtro_recursivo([0,1,2,1,4],1) returns [0,2,4]…
-
-2
votes1
answer46
viewsRecursive call that returns the beginning and end of a vector
Good afternoon! I’m very lost in this matter of a college job because I didn’t understand right recursion. Could someone help me? I need it here: A function that returns the index in which the…
-
-2
votes1
answer68
viewsRecursive function to mount file tree
I’m having trouble assembling a virtual directory tree with its respective files. The modeling is as follows: Table: folders id name company_id parent_folder (self relationship) I mounted the…
-
-3
votes1
answer164
viewsPython Recursiveness - Rest of the division of two numbers
I’m having trouble solving a problem in Python using recursive form: Make a recursive function that gets the rest of the split between two positive integers. Example: rest(33,5) = 3 Can you please…
-
-3
votes2
answers89
viewsrecursive exchange
''' Implement a recursive troca_recursive function she gets a list and two numbers (take and put) and returns the list, changing the number take by the put The first test takes the "simple case":…
-
-4
votes1
answer658
views