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
125
votes
10 answers

How does Tortoise's non recursive commit work?

I've checked out a copy of the SVN branch (my branch) locally to which I've merged from a different branch (which has a completely different folder structure). So basically there are a lot of deletions (of old files) and additions (of new files).…
user1447725
  • 1,363
  • 2
  • 10
  • 12
70
votes
30 answers

Post order traversal of binary tree without recursion

What is the algorithm for doing a post order traversal of a binary tree WITHOUT using recursion?
Patrik Svensson
  • 13,536
  • 8
  • 56
  • 77
49
votes
6 answers

Non-recursive os.walk()

I'm looking for a way to do a non-recursive os.walk() walk, just like os.listdir() works. But I need to return in the same way the os.walk() returns. Any idea? Thank you in advance.
Paulo Freitas
  • 13,194
  • 14
  • 74
  • 96
37
votes
13 answers

How to implement depth first search for graph with a non-recursive approach

I have spent lots of time on this issue. However, I can only find solutions with non-recursive methods for a tree: Non recursive for tree, or a recursive method for the graph, Recursive for graph. And lots of tutorials (I don't provide those links…
Alston
  • 2,085
  • 5
  • 30
  • 49
34
votes
15 answers

Help me understand Inorder Traversal without using recursion

I am able to understand preorder traversal without using recursion, but I'm having a hard time with inorder traversal. I just don't seem to get it, perhaps, because I haven't understood the inner working of recursion. This is what I've tried so…
Srikanth
  • 11,780
  • 23
  • 72
  • 92
17
votes
8 answers

How to rewrite Ackermann function in non-recursive style?

I have function public static int func(int M,int N){ if(M == 0 || N == 0) return M+N+1; return func(M-1, func(M, N-1)); } How to rewrite it in non-recursive style ? Maybe, is it implementation some algorithm?
BILL
  • 4,711
  • 10
  • 57
  • 96
16
votes
3 answers

SVN not updating recursively

A few weeks ago, I checked out our whole SVN repo in --non-recursive mode. Now it seems that when I do a svn up, it does not update the folder recursively. It's a problem because I'd like to get the changes from my colleagues without having to go…
aspyct
  • 3,625
  • 7
  • 36
  • 61
11
votes
3 answers

Rewriting a recursive function without using recursion

I'm rewriting some existing code in a setting where recursive calls are not easily implemented nor desired. (And in Fortran 77, if you must know.) I've thought about making a stack from scratch to keep track of the calls needed, but this seems…
Old McStopher
  • 6,295
  • 10
  • 60
  • 89
11
votes
2 answers

Non-recursive implementation of Flood Fill algorithm?

I'm working on a small drawing application in Java. I'm trying to create a 'bucket-fill' tool by implementing the Flood Fill algorithm. I tried using a recursion implementation, but it was problematic. Anyway, I searched around the web and it seems…
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131
10
votes
2 answers

How do I create a non-recursive calculation of factorial using iterators and ranges?

I ran into a Rustlings exercise that keeps bugging me: pub fn factorial(num: u64) -> u64 { // Complete this function to return factorial of num // Do not use: // - return // For extra fun don't use: // - imperative style loops…
dombo
  • 111
  • 1
  • 3
8
votes
3 answers

Non-recursive git log and diff

git log -p . only within the current directory but not in subdirectories equivalent svn log --diff --depth files . Is it possible?
bdimych
  • 291
  • 2
  • 8
6
votes
4 answers

Deep graph results in stack overflow: non-recursive serialization options?

We're getting StackOverflowErrors from Java's serialization library. The problem is that the default serialization implementation is recursive, the depth of which is bounded only by the longest path through a network of references. We realize we…
donlibes
  • 562
  • 2
  • 9
6
votes
3 answers

Binary Tree Maximum Path Sum, non-recursive, Time Limit Exceeded

I'm struggling with this problem, which I want to solve in non-recursive way. There seems no logic error in my algorithm, 73% test cases passed. But it can't handle the big data, reported "Time Limit Exceeded". I appreciate if somebody could give me…
xman
  • 183
  • 1
  • 12
5
votes
2 answers

Dynamic programming approach to calculating Stirling's Number

int s_dynamic(int n,int k) { int maxj = n-k; int *arr = new int[maxj+1]; for (int i = 0; i <= maxj; ++i) arr[i] = 1; for (int i = 1; i <= k; ++i) for(int j = 1; j <= maxj; ++j) arr[j] += i*arr[j-1]; …
F. P.
  • 5,018
  • 10
  • 55
  • 80
5
votes
7 answers

iterative version of recursive algorithm to make a binary tree

Given this algorithm, I would like to know if there exists an iterative version. Also, I want to know if the iterative version can be faster. This some kind of pseudo-python... the algorithm returns a reference to root of the tree make_tree(array…
Alex. S.
  • 143,260
  • 19
  • 55
  • 62
1
2 3 4 5 6 7 8