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
-
3
votes1
answer231
viewsHow to create an anonymous (Closure) recursive function?
In php, we can create recursive functions as follows. function quack($quack = 1) { if ($quacks >= 1) { echo "Quack"; $quack--; quack($quacks); } } Or, in case of avoiding problem with "renaming"…
-
3
votes1
answer546
viewsQuestions about Recursion in the Mergesort function [C]
I have a question about recursiveness. Actually, I’m not understanding how it works. Come on! I have the following function: void MergeSort (int *V, int inicio, int fim) { int meio; if (inicio <…
-
3
votes1
answer1467
viewsUsing recursion to count the number of times a number appears in a list
I created a recursive algorithm to count the number of times a certain number n appears in a list ls. It seemed to work if the list ls is quite small (between 10 and 100), but if it’s big, like…
-
3
votes2
answers1598
viewsRecursive function call - Python
I have a list of integers larger than zero. I need to identify the one with the largest number of divisors. For this I created three functions: one that lists, one that returns all divisors of all…
-
3
votes2
answers1010
viewsRecursive search in all directories and Ubdirectories of a given folder
I am developing a script to scan a particular folder for certain files and delete them or move them to another folder, according to some rules I already got answered in this question and in this…
-
3
votes1
answer1292
viewsWhy is a function calling itself?
def clinic(): print "Voce acabou de entrar na clinica!" print "Voce entra pela porta a esquerda (left) ou a direita (right)?" answer = raw_input("Digite left (esquerda) ou right (direita) e…
-
3
votes3
answers2001
viewsRecursive function with strings - Python
I’m having trouble solving an exercise. The statement is as follows: Implement the annoy(n) function that returns a string containing "annoy " (the word followed by a space) n times. If n is not a…
-
3
votes2
answers2577
viewsFind amount of times a character appears in a word using recursiveness
Develop an algorithm that reads a word (string) a character and return the number of times this character appears in the word. The algorithm must be recursive. Examples of Input and Output: Entree:…
-
3
votes1
answer420
viewsTime complexity of recursive palindromic algorithm
I need to analyze the time consumption of my algorithm for a size vector n = f - i + 1, through a recursion, to then define a closed formula. public class ehpalindromo { public static boolean…
-
3
votes2
answers144
viewsRecursive printing in triangle format
I have to read an integer value and pass it as a parameter to a function. It should display the number using the sample format. Ex: if the number given was 3, show: 1 1 2 1 2 3 I can show the format…
-
3
votes1
answer48
viewsProblems with recursion in c
I’m trying to learn recursion and I’m doubtful on a question I was doing in c, I need to add up how many numbers of a vector with n elements are larger than a number x. This recursion just doesn’t…
-
3
votes2
answers460
viewsRecursive or loop method to popular or list an n-dimensional array
I’m trying to build a method capable of filling an n-dimensional matrix in all positions, for example: I have a 2-dimensional matrix, where this matrix is 2x2 with only 2 dimensions in a Cartesian…
-
3
votes1
answer257
viewsRecursiveness and Haskell
How to define recursively in terms of multiplication, the power function, where a base is raised to a non-negative integer exponent? Code: expo (x, y) y > 0 fun(pot) return x*expo(x, y-1)…
-
3
votes2
answers784
viewsRecursive Function in Typescript Returning Array with Dynamic Objects
I am beginner in Typescript and tb in Javascript, so I confess not to have much knowledge of the language, therefore, I will describe my problem. I have the following table in a Postgres database:…
-
3
votes1
answer129
viewsHow to make a recursive sum on a JSON object in Angular 6?
Using Angular 6, how could fill the field total representing the total number of direct and indirect bosses of each employee? I have the following data: const employees = [ { id: 1, firstName: 'a',…
-
3
votes2
answers920
viewsRecursiveness: Compute the sum of the first positive odd values starting at 5
I’m doing some exercises on and I stopped on this a few days ago. I got to the following code: /** * Funcao: Soma dos primeiros valores ímpares positivos começando em 5. * @param quantidade -…
-
3
votes1
answer156
viewsConditional Operations Error in R
I am programming a simple recursive algorithm to compute the Fibonacci sequence in R, as I do in C. Follow the same below: fibonacci <- function (n) { if (n == 1L) return (0L) else if (n == 2L ||…
-
3
votes1
answer116
viewsHow to transform an array recursively?
I have the following array: let exemplo = [{ alarm: { title: "Pai", id: "1" }, children: [], parent: "", }, { alarm: { title: "Filho", id: "2", }, parent: "Pai", children: [], }, { alarm: { title:…
-
3
votes1
answer84
viewsQuickly access exact element instance within List java
I have a list that will be filled with many points (x, y, z) - about 3000. Each point is unique within the list (no repeated points). At some point my program needs to recover the instance of a…
-
3
votes1
answer54
viewsDifference between changing a variable and a recurring object
I’m recurring in two situations: one changes an object field and the other directly changes the string. What is the difference between these two forms of return since it gives different result?…
-
3
votes1
answer97
viewsHow to make a list of recursive iterations - Python
I am implementing a python Hanoi tower and I need a log of all moves. It could be a list of the states of the 3 stacks. But when I try to use the append function for this list/log, the result is the…
-
3
votes2
answers145
viewsRecursive method to display the representation of an integer in a base
Write a recursive method base() which accepts a non-negative integer n and a positive whole 1 < b < 10 and present the basic representation b of the whole n. >>> base(0, 2) 0…
-
3
votes1
answer183
viewsPython recursive method that returns how many times a given element appears in a vector
I want to make a recursive method in Python that returns how many times an element appears in an array. Below follows my code using binary search: def binaryrec(valor, itens, menor, maior): vezes =…
-
2
votes1
answer139
viewsDoubt in the complexity analysis of an algorithm
I need to know how to compute the complexity of this algorithm using the recurrence equation. public int qdr(int x, int n) { if(n == 0) return 1; else return x * qdr(x, n-1); } It is a recursive…
-
2
votes2
answers292
viewsLeader and Java Recursion Led Logic
I have a relatively simple problem to solve, but I’m not succeeding because of a logical deficiency. My problem is this:: I have a hierarchy of leaders and leaders. For example: Lider 1 Lider 1.1…
-
2
votes1
answer685
viewsLinkedlist Recursive Method
I’m having trouble implementing a recursive method for inserting an element at the end of a simply chained list. Below is the Iterative method: public void addLast(Node<E> novoNodo){…
-
2
votes1
answer288
viewsRecursive in Cakephp - Explanation
I would like to know, for example, how the recursive cakephp. $this->Model->recursive=2; What he does exactly, in practice?
-
2
votes1
answer130
viewsWhen using recursion method returns 0
I have the following code: public int lerInt() { String entrada = ""; int saida = 0; try { entrada = input.readLine(); } catch (IOException e) { System.out.println("Falha critica."); } try { saida =…
-
2
votes1
answer701
viewsCapture double quote content with recursion with Regex
I need to capture double quotes with Regex in PHP. I tried using line-breaking recursiveness in several ways, but to no avail. I’ve combed through several topics and researched how to do that, but…
-
2
votes1
answer2062
viewsList all properties of a C#object?
I need to write all the primitive properties of a C# object regardless of how many "levels" I enter these objects. I have the following object in Javascript: var objeto = { propriedade:{ valor:42 },…
-
2
votes1
answer1011
viewsMove all files with the . prj extension to a folder
I would like to know whether the following situation is possible: There are several folders inside each other... and within them there are files with the extension .prj. It is possible to read all…
-
2
votes1
answer4641
viewsHigher value of a vector, with recursion
I’m studying recursion and vectors, but I can’t understand how this method works, which returns the highest value using recursion. int maximoR (int n, int v[]) { int x; if (n == 1) x = v[0]; else {…
-
2
votes3
answers6084
viewsRecursive palindromus C
My functions are not working properly, always the program tells me that it is not palindromic, for any situation. Follow the code: #include<stdio.h> #include<string.h> int inverte (char…
-
2
votes2
answers323
viewsPython accumulator list
I am developing a function that takes 3 parameters fctn(Function, list, element) and that it has to return a list with the intermediate states of the accumulator, as in the example below:…
-
2
votes0
answers99
viewswxmaxima. Defining a function of three variables
I’m trying to do some symbolic/algebraic calculations in wxmaxima. But I’m having syntax problems. Question. Let 'n' and’m' be previously stipulated integers. What is the syntax/'command line', as…
-
2
votes1
answer64
viewsRecursion in C - The crash program
The goal of the program is to ask the user for two digits and generate a list of sequences, each containing information from the previous. For example: User writes 1 1 and the generated list is: 21,…
-
2
votes1
answer527
viewsRuntimeerror: maximum number of recursive calls exceeded - python
fibonacci_cache = {} def fibonacci(n): if n in fibonacci_cache: return fibonacci_cache[n] if n==1: value=1 elif n==2: value=1 elif n>2: value=fibonacci(n-1) + fibonacci(n-2)…
-
2
votes3
answers732
viewsRecursive function with for
I’m studying recursive functions and I came up with a question when I was looking at some algorithms that use recursive function and for. I decided to create a simple example and print some values…
-
2
votes1
answer35
viewsVector Search - Arrayindexoutofboundsexception
I’m building a function that does a linear search on an arrangement. What I would like is that instead of leaving in the call the value of the size of the arrangement, I would like to use the…
-
2
votes1
answer123
viewsError in recursive logic
My recursive function needs to calculate the power from b to N is giving error "Segmentation failure (recorded core image)", which can be? My job: int potencia(int b, int n, int a){ if(n == 0){…
-
2
votes1
answer759
viewsWhat is a recursive method?
The variable resultado within the for is recursive? #include <stdio.h> int main(void) { int N,i; double resultado=0.0; scanf("%d",&N); for (i=0; i<N; i++) { resultado= 1.0 /…
-
2
votes1
answer641
viewsTip on how to turn loops into recursive function
This program takes the professional aptitude test based on the logic of Fuzzy relations. I have to turn these loops into a recursive function, researched and even understood how a recursive function…
-
2
votes2
answers203
viewsExplanation of recursive functioning
I’m at the beginning of system analysis studies and I’m learning programming language. In C language studies I started to see recursiveness and some codes that have recursiveness I get lost and end…
-
2
votes1
answer1458
viewsRecursive function that returns the sum of the digits of a number
I need to create a recursive function that takes a number n integer and returns the sum of the digits of this number. I made the following code but it’s giving None: def somadig(n, s = 0): if n >…
-
2
votes1
answer659
viewsJava Recursion - MDC
How can I implement a counter in the code below to know how many recursive calls will happen to calculate the MDC of 14 and 18? package Aula01; import javax.swing.JOptionPane; public class Exer01 {…
-
2
votes1
answer61
viewsRecursion problem, C language
I have a problem, in a code I found where it receives a string from the user and returns it reversed, doing this recursively. However, I do not understand why the function made can actually do this.…
-
2
votes1
answer509
viewsCalculate the Cartesian product with functional programming
I’m writing a Python function that takes two lists and returns a list of tuples with the Cartesian product of the input function. I cannot use any ready-made Python library function. Ex:…
-
2
votes1
answer83
viewsPython recursive function
I need to build a recursive function in Python that takes an integer n and print to zero and then go back to n. Example: n = 5; > 5 4 3 2 1 2 3 4 5 Until then I built a function, but it only…
-
2
votes1
answer1226
viewsDoubt about Recursiveness in a Power Method
I didn’t understand how recursion works in the method that performs potentiation. public class calculaPotencia { static Scanner scan = new Scanner(System.in); public static void main(String[] args)…
-
2
votes1
answer72
viewsDual recursion in a function, how does it work?
I understand what happens in recursion when there is only one recursive call, I understand well how to write an output condition for recursions. But I have difficulty understanding when there are…