# LaVOZs

The World’s Largest Online Community for Developers

'; Newest 'recursion' Questions - LavOzs.Com

# 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.

• ### How does recursive division to generate maze work?

So ive been wanting to generate a perfect maze! So i wanted to use the recursive divison algorithm. However, I dont really get how the algorithm will generate a perfect maze, i dont know what im ...
• ### Recursive Sum in C++ [closed]

Could you please let me know how to fix the output to be 5? This is a Hackerrank challenge in C++. Input: ...
• ### Time complexity for a greedy recursive algorithm

I have coded a greedy recursive algorithm to Find minimum number of coins that make a given change. Now I need to estimate its time complexity. As the algorithm has nested "ifs" depending on the same ...
• ### speed up appending 3 dimential data to ndarray

I have a problem with efficent when I try to append readed images using cv2 library. My readed img are 200,200,3 ndarray. When I try append about 14k images to created empty array using np.empty((200,...
• ### Palindrome creator using javascript and recursion

I need to create a function that takes a number and returns palindrome of this number, by summing its reverse number. For example 312 + 213 = 525. But what's more important, I must use recursion in ...
• ### Kernel visibility into the call stack in Python

Does the OS have visibility into the call stack (e.g. calls made between functions) in CPython? E.g. In what way is the OS involved in the creation, retrieval and/or management of the Python stack and ...
• ### Relating backtracking to Dynamic Programming to DFS?

Looking at discussion for this coding problem: https://leetcode.com/articles/jump-game/ I'm trying to clear the confusions I have by finding the relationships (not the definitions) between ...
• ### Build binary search tree using dictionary in Python

I'm trying to build a BST (binary search tree) with dict in python. I do not understand why my code is not adding nodes to the BST. I saw a similar post here: How to implement a binary search tree in ...
• ### Python Code optimizer for list of list choices conbination

I have python code to find all the possible choices from the list of lists. But when I have a big size list it gives a larger possible dataset. My function is, def yield_combos(lst): if not lst: ...
• ### Solving tower of Hanoi with given arrangements

I was wondering that say given an arrangement of valid tower of Hanoi pegs, for example suppose peg [2,2,0] or peg [0,2,1] (let's say the the index of the array are identifiers of each peg, the peg ...
• ### Python recursive powerset function for tuples

I am trying to create a function that returns a powerset (all subsets of a given tuple of numbers) in the form of a tuple of tuples. I have followed code that I have found previously, but this ...
• ### Recursive computation using variable templates - gcc vs clang

Consider the following example: #include <cstdio> template <int N> int fib = fib<N - 1> + fib<N - 2>; template <> int fib<2> = 1; template <> int fib<1&...
• ### Get Elements from tree at given level

I would like to get all integer keys at a given depth/level of a tree. The solution I tried looks like this: public LinkedList<Integer> keysAtDepth(int depth) { return getGivenLevel(depth, ...
• ### Is T(n)= T(n-1) + n always n(n+1)/2 or O(n^2)

I watched a video where they prove T(n)= T(n-1) + n is O(n^2) I have the following expressions which are: T(1) = 4 T(N) = T(N – 1) + N + 3, N > 1 My question is, is the expression above solved ...
• ### Traverse Binary Search Tree Pre Order recursively

I am trying to traverse a BST Pre-Order recursively but I can not make it work. This is what I've tried: public String PreOrder() { return preOrderStringBuild(root, ""); } public String ...
• ### String return value in recursive function in java

So I'm practicing java currently, I'm a beginner and I try to explain all the examples that I code so I can understand how and why things are like that. I understand the concept of recursion but I ...
• ### Python - 4 in a row - recursivly check all possibilies and check where to put coin to win

Basically I wrote a script which has a class four_in_a_row which has functions to check if someone won, claim a point for a player and print the current status of the game(where which "coins" are). I ...
• ### Recursion with Observables and http get [closed]

I know, there are several similar topics, but i was not able to transform the other solutions to my own problem. Here is what i have: loadMoreMovies(page: number, query: string, genres: Genre[]): ...
• ### Why is my backtracking algorithm not working for this simple problem?

Hi I am currently trying to solve the following problem: Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of ...
• ### Difference in seemingly same returns [duplicate]

here are 2 functions (minor and minors) that I wrote which give same result but miniors gives me an error that is index out of range, please help me understand my mistake deter=[[1,2,1,1], [0,...
• ### How to implement get() recursively

I was wondering what I am doing wrong with my get method. I've done this before using loops but I cant seem to get the same using recursion. My size() method works with recursion but I am very ...
• ### Tree recursion - Print subsequence of a given number

For the below recursive problem implemented in GoLang: package recursion import ( "fmt" "strconv" ) // m is the number, n is upto-length of subsequences // m = 20125, n =3 should print 201,...
• ### Recursive Binary Search for Integers [duplicate]

I have tried implementing the divide and conquer technique of binary search using recursion. The code for it can be seen below. I think when the program is run, I'm getting stack overflow. If anyone ...
• ### How to render HTML template for all nodes on-click - using Django mptt tree

I have setup a Django mptt tree which is displaying the tree correctly. The nested tree consists of 2 types of objects (reseller and customer - added in model). The reseller menu can be nested before ...
• ### How does it effect the application if i increase the recursion limit in python [closed]

I was solving a problem on Hackerrank where I got error- maximum recursion depth exceeded. Is it okay to increase the recursion limit or that should be avoided? Also what adverse effect does it bring ...
• ### Breaking Out Of Recursive Loop JS [duplicate]

deepSearchObject(obj) { let duplicateExists = false; Object.keys(obj).forEach(key => { if(key === 'fieldCode') { let value = obj[key] if(this.fieldCodes.includes(value)) { ...
• ### Unable to interpret recursive loop output

i am unable to guess the output after 'Hello 1' below. Why does system print 0-9 integers? public static void number(int count) { if(count==0) return; else { ...
• ### Python RecursionError

(I'm a total beginner) I want to write a recursive function which can tell me if a number is a prime number or not: but I keep getting the same recursion error : here is my code : from math import * ...
• ### Why is my function returning None instead of a number?

Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers. ...
• ### Recursive function for sum

I have this recursive function, and I try to pass the result in 's' variable. However if I use *s=*s+v[i]; the function works. But if I try to call sum(v,i+2,s+v[i],n); It doesn't work anymore. Can ...
• ### How do I stop recursion in depth search PHP?

In this function that I use to search some element in a tree ,how can I stop the recursion when I found the seached element? public function find(\$element, \$found_path){ var_dump(\$element->...
• ### Tree recursion - How to avoid 'missing return at end of function'? [closed]

For the lab problem of insects combinatorics, below is my solution using tree recursion: func Paths(m int, n int) int { length := m width := n var f func(int, int) int f = func(h ...
• ### Issue regarding arranging array elements in tree structure [duplicate]

I want to arrange array elements in hierarchy base on [parent_page] key. the element which have parent_page =0 will be root elements and all other array elements will fall under child key of its ...
• ### What is the recursive function used in this problem of finding ways to climb a staircase?

Problem Statement Suppose there is a staircase that you can climb in either 1 step, 2 steps, or 3 steps. In how many possible ways can you climb the staircase if the staircase has n steps? Write a ...
• ### Can you check if i do this recursive method correctly?

Here is the question: There are n switches in the campus. You are required to create a mesh topology for the switches. Write a recursive method to returns the total number of connections required for ...
• ### Convert a non-recursive function to recursive - C++

I've written a C++ code which computes failure links in KMP algorithm, but what I really need is to write this code in a recursive way and I have no idea how to do this. I know about recursion, but I ...
• ### The empty array in this recursive code is accessible how?

I have looked at this long and hard. I understand recursion, I understand the call stack and the concept of “Last in, first out” but in this example. function countup(n) { if (n < 1) { ...
• ### C# anonymous function recursion

Please correct me if I am wrong but I could not find anything straight forward like this online. Assuming you have the following: static Func<int,int> GetInt(int n) { ...
• ### Is it possible, in general, to transform a recursive function in one that uses a manual stack in JavaScript?

Mind the following function: function count(n) { if (n === 0) { return 0; } else { return 1 + count(n - 1); } } It is the simplest recursive function that counts from 0 to N. Since ...
• ### Optimal strategy for two player coin games

Two players take turns choosing one of the outer coins. At the end we calculate the difference between the score two players get, given that they play optimally. The greedy strategy of getting the ...
• ### How to solve factorial even numbers on the n number, then multiply them

For example there are 3 then the program will multiplying the first 3 factorials 2 x 4 x 6 = 48. For example if the user wants 3 then the program will multiply the first 3 factorials only and the sum ...
• ### Recursion not properly running?

I'm practicing recursion, and am trying to use it to constantly add individual digits in a number until there is only 1 digit left. Basically, if the number is 84, it becomes 8+4 = 12 which then ...
• ### Return statement is not working in python inside if condition [duplicate]

def digital_root(n): s=0 if n < 10: return n else: while n>0: s+=n%10 n=n//10 digital_root(s) I am having trouble submitting this ...
• ### Is DP helpful only in recurisve problems?

is Dyanamic Programming helpful only in recursive problems , Can it be used in Some other use cases or problems?
• ### Remove item recusively from tree

I'm trying to create a tree component. But I dont know how remove a item recursively inside a tree. Each item its created dinamically and I would like remove an item/branch of the tree in each level. ...
• ### Nested Predicates In Prolog

I am trying to write a predicate that ‘exists’ inside the ‘scope’ of another predicate . The reason I need this is because both predicates make use of the same very large parameters/arrays and the ...
• ### How to turn 2 for loops into pure recursion?

I am wondering how I turn this piece of code so it only uses pure recursion, so no for or while loops and list comprehension. def things(list1, list2): stuff = [] for thing1 in list1: ...
• ### string index out of range/ invalide syntex

I got an error as "string index out of range" on running code in the command line while it gives the " invalid syntax" as the error in VS code terminal here is my code def copy(lst1, lst2 = []): ...
• ### What's the time complexity to find all substrings?

I made this code to generate all unique substrings given a string, and I'm struggling to find the complexity of the code when I use recursion. I think a good complexity of time for this problem is O(N²...
• ### Recursively going through list and compare with a value (python)

The task is to go through a list, compare it with a value and then return the amount of times the value occurred. The comparison works and when I find the matching value I want to save it in a list. ...