Questions tagged [non-recursive]

non-recursive programming avoids risks of recursion by using iteration instead.

In several programming languages, recursion can lead to out-of-memory problems, using non-recursive approaches can avoid this risk.

120 questions
0
votes
3 answers

java: Non-Recursive Depth First Search using ArrayDeque or LinkedList or LinkedBlockingDeque?

public void traverse(Node root){ ArrayDeque queue = new ArrayDeque(); queue.add(root); while(!queue.isEmpty()){ Node currentNode = queue.pollFirst(); List nl = getChildrenfromDB(currentNode); …
KJW
  • 15,035
  • 47
  • 137
  • 243
0
votes
0 answers

Trying to understand this non-recursive Heap's Permutation Algorithm

Right now I'm trying to understand why a certain non-recursive implementation of the Heap's Permutation Algorithm works. I implemented some code of this particular version of the algorithm in python, but I don't understand the logic behind what…
0
votes
0 answers

Non-recursive mid-order traversal binary trees cannot output a complete result

When I use the stack to deposit the root node,only A B two root nodes can enter the stack, and then the program ends input: AB@@C@D@@# output: BA Stack definition, initialization, judgment whether it is empty, into the stack, out of the…
0
votes
1 answer

Is there a non-recursive solution in Python for the egg breaking problem with 102 floors and 7 eggs?

I am a novice programmer learning Python using the book: "Introduction to Computation and Programming Using Python" by John V Gurrag. I am attempting a finger exercise in Chapter 3: "The Empire State Building is 102 stories high. A man wanted to…
0
votes
0 answers

Checking for exlusion resrtiction (formally) in GSEM

I am performing simultaneous equation regression using gsem in stata. My model is nonrecursive. Identification of such a model requires the use of variables that serve as instruments. I want to ask if there is a formal way to check for the…
Rupali
  • 1
0
votes
1 answer

How to convert recursive tree search function to nonrecursively?

I'm trying to explore the binary tree. However, I have to implement recursive functions nonrecursively. I've searched several ways to convert recursion to nonrecursive. But it doesn't seem to apply to my code. I wonder if I can convert my code to…
sapi
  • 1
  • 2
0
votes
3 answers

Writing a non-recursive function as maximum recursion depth has been exceeded

I was wondering if someone could help me rewrite this code as non-recursive so it can compute higher numbers, my current code looks like this: def T(n): if n < 3: return n return T(n - 1) + 2 * T(n - 2) - T(n - 3) The function is…
ThomasL123
  • 25
  • 4
0
votes
1 answer

Javascript how to implement n-dimensions to removeOne with non-recursive

input console.log(removeOne([])); console.log(removeOne([1, 3, 1, 2, 1])); console.log(removeOne([1, 4, [1, 5, 1, 2]])); console.log(removeOne([1, 1, [1, 3, [1, 1, 4, 1], 2]])); output [] [ 3, 2 ] [ 4, [ 5, 2 ] ] [ [ 3, [ 4 ], 2 ] ] function…
55555555hh
  • 13
  • 2
0
votes
0 answers

Receiving CTE syntax error with 10.1.48-MariaDB-0ubuntu0.18.04.1

Beginner with MariaDB and trying to understand the syntax. I’m trying to create the simplest example and then build from there. Shouldn’t the following work? with myCTE as (SELECT 1 as MyNum, 'A' as MyChar UNION SELECT 2 as MyNum, 'B'…
0
votes
0 answers

Describing QuickSort Algoritm

Im having a problem to understand this algorithm, how would you describe it, mostly the while loops. I understand that this i an iterative function, and the use of Hoare partition scheme. But what does the while loops do, and why does it use…
j0can
  • 21
  • 6
0
votes
1 answer

member access within null pointer of type, C programming is Palindrome

I am trying to solve isPalindrome() question on LeetCode using non recurisve solution, When i run this code using VSCode it runs and gives me the right output, but when i run it in LeetCode compiler it gives me the error mentioned below. Can you…
0
votes
1 answer

Is async code in a Promise always an antipattern?

I see from this question that it can be an antipattern to mix Promises with async code. Does this, however, apply in all cases? I can't see an easy way to avoid combining them in the following code: It's an alternative to setInterval which waits…
0
votes
2 answers

Create a tar file in a subdirectory of the directory to be archived

I'd like to create a tar file of all the files in a directory minus sub-directory's in that directory and place that tar file in one of the sub-directory's. For example, I have several .txt files in /test and also another directory in /test called…
Ben
  • 2,058
  • 9
  • 29
  • 39
0
votes
1 answer

Convert recursive function to a loop (ternary operator)

so I have this code from an exam question and I have to convert the recursive part with a loop, now I tried many times but the loop will be endless, here what I did: code with recursive int f(int n, int m) { int k; if (m == 0) return n; …
0
votes
0 answers

How can I turn this Recursive program to Dynamic one?

I got below recursive function written in Java. I wanted to convert it to a Dynamic program but I don't know it is right or not? I think I'm missing something here. Any guidance would be perfect. //Prints newRec(4,4) for example. public static int…
Ramazan Kilimci
  • 109
  • 1
  • 7