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
-
1
votes1
answer68
viewsLogic of function loop
I’m starting study of functions in Javascript and analyzing the loop below came to me the question about the logic of the result. function foo(i) { if (i < 0) return; document.writeln('begin:' +…
-
1
votes3
answers129
viewsRecursion - add numbers to an array
I am taking the course of Freecodecamp and on the subject of recursiveness I came across this code: function countup(n) { if (n < 1) { return []; } else { const countArray = countup(n - 1);…
-
1
votes0
answers113
viewsRecursiveness - Why am I entering a loop?
I’m trying to implement an algorithm called Minimax, but I’m finding problems in effecting its recursion, it goes into a loop that I can’t identify why. The depth of the algorithm should vary…
-
1
votes1
answer750
viewsRecursive function to calculate the mean
I did that job media() that averages the elements present in a vector of 5 elements. However, the function is returning 2 instead of the correct average. #include <stdio.h> int media(int…
-
1
votes1
answer56
viewsPython recursive function printar correctly
I am starting in python and I would like the result of my execution to be as follows: [ [ 0 , 1 , 2 ] , [ 3 , 4 , 5 ] , [ 6 , 7 , 8 ] , [ 9 ] ] [ ’ ∗ ∗ ∗ ∗ ’ , ’∗ ∗ ∗ ∗ ’ , ’ ∗ ∗ ’ ] But I’m not…
-
1
votes1
answer755
viewsRecursively counting sequence of numbers in a C matrix
So I have the following problem: I need to count how many decreasing sequences of numbers there are in a matrix recursively, but it is only considered a sequence if it is completed to number 1. Ex:…
-
1
votes0
answers53
viewsLogic about recursive return
Hello guys I am studying binary tree search and recursiveness is very used in this type of data. I have a question, for example, I did the following function to search for an element in the tree:…
-
1
votes2
answers926
viewsRecursive function to calculate the number of lowercase letters in a character string
I was able to do a function to return a given character at an X position of a string: public static char funcao (String texto, int indice){ if (indice == 0){ return texto.charAt(indice); } else {…
-
1
votes2
answers65
viewsSum of n + last digit on the left
I have a recursion challenge. The goal is to return "n + the sum of the last digit on the left". Example: Input: 54321 Output: 54326 (54321 + 5) But the only way I could was like this: #include…
-
1
votes2
answers422
viewsFinding students without a class - Python / Excel
I have a spreadsheet in Excel with all my students and their respective grades (5th to 9th). I need to find all my students who aren’t in any class. Through the Excel filter I can do, but I have…
-
1
votes0
answers68
viewsHow to calculate the values of a function in an entire range when only the values in the integers are known?
someone can help me, please? I’m trying to write a function in Python (I use 3) that implements the following code that is in Mathematica:…
-
1
votes0
answers46
viewsReduce and simplify redundant sql (mysql) query for financial reporting (account hierarchy)
I have basic knowledge of database and Mysql, I wonder if someone could help me decrease the 'size' of a query and its redundancy (facilitating future maintenance). This is a financial report with a…
-
1
votes1
answer123
viewsRecursive Hanoi Tower with Play Counter
I wrote this recursive code from Anoi’s tower and was trying to implement a section that told me the minimum number of moves needed and what move we were playing ( add a move whenever it changed).…
-
1
votes2
answers89
viewsHow to call a function within itself? Recursiveness
Goal Make a recursion within the function SALVARHISTO() so that the function is called again, if the cell A8 is not found. What I tried to I tried to put a condition at the end, if the A8 cell was…
-
1
votes2
answers161
viewsRecursiveness in Java
I’m trying to create a recursive method, which shows me all the cost centers children who do not have other children, for example: If the father is the cost center 1, will return me the 3, 4 and 5.…
-
0
votes2
answers185
viewsLoop to repeat the previous keys (3, 32, 321, ...)
I’m trying to make a breadcrumb dynamic and need to make a loop to mount the link. At each loop, it needs to repeat the previous items, as in the example below the array and the output. array(…
-
0
votes0
answers217
viewsStackoverflow in AVL Trees
The program I am running, intends to simulate a system that counts the passage of cars through gantries, for this the program receives several types of commands and does not end until receiving an…
-
0
votes0
answers73
viewsHow to calculate the number of solutions to a puzzle using recursion
As an accurate work to develop an algorithm that calculates the amount of possible answers to a puzzle, the game consists of an arrangement of n black/white pieces, when a piece is removed the…
-
0
votes0
answers94
viewsRecursiveness of folders and files stored in the Database - PHP
I have a system using Cakephp, in one of the pages there is the possibility to register folders and recursive files, which are saved in the database. Now, I need to query these folders and files…
-
0
votes1
answer132
viewsRecursion in Python
I am trying to make a recursive function in Python that is not assigning me the correct results and when I try to change it it always happens stack overflow. This is my code: def sublistas(lista):…
-
0
votes1
answer244
viewsHow to keep a fixed value within a recursive function?
I would like to create a variable with the first value passed as parameter in a function, but every time a recursive call is made the variable receives the value of the new parameter passed. For…
-
0
votes2
answers400
viewsI need my php function to be recursive
I need this function to be recursive, I’m beginner in php and I’m not quite sure how to do this. :/ <?php function mostraArray() { $cena=array($_REQUEST["numeroa"], $_REQUEST["numerob"],…
-
0
votes2
answers469
viewsSum recursive sequence
I am implementing a recursive code that adds the following sequence: x + x 2 / 2 + x 3 / 3... x n / n, for this sum, I thought of a definition, combining two recursive functions, as follows below,…
-
0
votes0
answers28
viewsHow to escape a recursive process of saving error log from a database - PHP?
I have a class that saves the log in a database based on any transaction error on that basis. The fact is that the process of saving this log tbm is a transaction and in a hypothetical scenario any…
-
0
votes1
answer2102
viewsC ordering using recursion
I need to make a vector ordering code using recursion. I looked into the sorting methods and found two that would be interesting: Lection Sort and Quicksort. However, I tried to use Selection Sort…
-
0
votes0
answers578
viewsNumerical recursive sequence in Java
I need to do a numerical sequence in recursive mode that, after arriving at the n number (5, in the example), starts to do the inverse sequence. Example: 1234554321 I’ve done what the normal…
-
0
votes1
answer148
viewsTuples: index out of range - recursion
I have a problem with index out of range in my tuple. The purpose of the code is to create a recursive function that finds a substring inside a tuple with elements of any kind. Someone could help me…
-
0
votes1
answer582
viewsCalculation of Ruby Factorial
Create a Ruby script that reads 10 whole numbers and store them in an array. Then the script should calculate the factorial of each of these 10 numbers, and store the results in another array, and…
-
0
votes1
answer319
viewsjava.lang.Stackoverflowerror: stack size 1038KB
I’m making an algorithm that converts one bitmap leaving it in shades of gray. I could do it using for but I’d like to do it recursively. Using for (This working well) //BUTTON - ON CLICK . . .…
-
0
votes1
answer510
viewsCounter of recursion solutions
Hi, I made a recursive Sudoku program, it’s working fine, but I’d like to add a solution counter, I’ve tried numerous code changes that would make it possible, but it didn’t work, finally I tried a…
-
0
votes2
answers57
viewsProblem in a function parameter
#include <stdio.h> #include <stdlib.h> int pos_setinha(int x); void menu(int x); int main() {int x=0; do { menu(pos_setinha(x)); } while(1); } int pos_setinha(int x) { x=0; char C;…
-
0
votes1
answer100
viewsAlgorithm of Division and Conquest
I’m having trouble making a division and conquest algorithm of the sum of the elements of an arrangement. public static int somatorio(int[] a, int numElem) { if(numElem == 0) { return 0; }else…
-
0
votes1
answer453
viewsFUNCTIONAL PROGRAMMING: Recursive function to calculate the rest of the division between two positive integers in ELM
Hello, I’m having trouble making a recursive function that passes as a result the rest of the division of two integers into ELM. I was able to perform the function without recursion as shown in the…
-
0
votes2
answers489
viewsRecursive algorithm to check if an element belongs to a list
I have to do a recursive function that takes a list and a target element, and returns True, whether the element is in the list; and False, otherwise. EXAMPLES: busca([1,2,3], 2) --> retorna True…
-
0
votes1
answer1487
viewsChained list in C - Reversing nodes recursively
I’m following the notes of Algorithm Projects by Professor Paulo Feofiloff, and I’m having a hard time solving a question from the Chained Lists, transcript to follow: Exercises 5 Write a function…
-
0
votes2
answers350
viewsRecursive algorithm for calculating arithmetic mean
I am making an algorithm that has to calculate the average values of a list, but with what I did does not present the correct result. The sum works, but when it comes to dividing, no. def…
-
0
votes0
answers135
viewsKnapsack Problem (Backpack Problem) SQL SERVER CTE RECURSIVE
Good afternoon. I am trying to develop a solution within the ERP of the company in which I work, with the objective of identifying the possibilities of INVOICES summed whose TOTAL is equal or…
-
0
votes1
answer43
viewsIterate over components Swing recursively is strange
To add Listeners to all components of my Frame I’m iterating on it recursively: private void adicionarListeners(Component componente) { Stack<Component> stack = new Stack<Component>();…
-
0
votes2
answers1681
viewsRecursive even numbers in C++
The purpose of the code below is, through a recursive method, to return the number of even numbers between two numbers placed by the user. I can’t understand why my method quant only returns 0.…
-
0
votes1
answer34
viewsRecursions in closures
# -*- coding: utf-8 -*- def memoize(limit, *, message = 'Limit exceded'): count = 0 def inner(func): cache = {} def wrapped(number): nonlocal count if count < limit: if number not in cache:…
-
0
votes1
answer202
viewsProblem to list directories with java
I’m trying to list all the files in the C: directory on my PC. Smaller directories with 11 thousand files is picking up normally, it takes a while, but it’s no problem. The problem is when I will…
-
0
votes1
answer146
viewsMount recursive function for Treetable
I’m trying to build a tree of folders and questions with Java, Jsf and Primefaces. I have two lists, one is the one that saves the folders and subfolders, and another list is the one that assembles…
-
0
votes1
answer172
viewsRecursive query does not return records when the parent product and the child product have the same code
I have a table that maps a production line. The fields are: Product: Machine Output Product. Parentproduct: Input Product. Machine: Code of the machine. I’m using CTE s to get the data recursively.…
-
0
votes0
answers47
viewsDecimal to C binary conversion program
The exercise I’m solving asks to write a program in C(pointer, dynamic and recursive allocation) that prints a given integer on a binary basis. My result is generating a very large number, now I…
-
0
votes2
answers295
viewsWhat’s the difference between using Return and print in this recursive function that calculates the sum of numbers?
I made a simple function in Python to give me the sum of the numbers n until 0: def retorna(n, zero, soma): if n <= zero: soma += n return soma retorna(n+1, zero, soma) ret = retorna(1, 5, 0)…
-
0
votes2
answers195
viewsRecursiveness using Python
I am trying to create a recursive function that takes a positive integer number N and prints all even numbers from 0 to N in ascending order. I’m only managing to do the opposite, that is, print the…
-
0
votes1
answer404
viewsLoop without repeating Nodejs + mysql data?
I need to insert the DESCRIPTION field into a CATEGORY table; I have my data in JSON format (already on the server); My loop runs the sequence of steps: Checks whether the "category" field exists in…
-
0
votes1
answer183
viewsProblem to add at the end of a Simple Chained List
I have a simple chained list and need to do a recursive function that adds at the end of the list an element, I already have the function without recursiveness, but the with recursiveness is giving…
-
0
votes1
answer259
viewsHow to perform a recursive query with the relations stored in a JSON array?
I have a MYSQL table that relates to itself. The relations are represented in the same table through a JSON Array. Here is the table and some sample data: CREATE TABLE `templatedata` ( `Id`…
-
0
votes0
answers175
viewsVBA programming - Recursiveness, boolean backpack
I have a similar situation to boolean backpack. I have a table with N lines. Column 'A' contains a length (m²), column 'B' contains a price (R$). I need to get all possible sums from column 'A' up…