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
2 answers

Iterative Threaded Binary Tree Traversing with only constant extra space

How to traverse a threaded binary tree non recursively in O(n) without using a stack (just allowed to use constant extra space for temp variables, so we can't add visit flag to each node in the tree). I spent a good time thinking about it but it…
K''
  • 5,020
  • 7
  • 33
  • 43
-1
votes
1 answer

EDITED: Binary insertion not working as I think it should

Still newish to Java; our professor wants us to use a non-recursive binary search AT THE TIME OF ADDING elements to this ArrayList. I keep getting outofbounds exceptions, and I just can not find out why. I also notice unusual behavior while…
Dragon Wolf
  • 61
  • 1
  • 2
  • 11
-1
votes
1 answer

Iterative Quicksort

I'm trying to implement a quicksort method that runs iterativly. I have used stack to hold the information. It will also use partitions to achieve this. I know that the partitioned section of code at the bottom is fine, it's only the first block of…
Crypto
  • 19
  • 1
-1
votes
1 answer

How to make this function non-recursive?

Hello it was suggested to me that I learn to write things non-recursively to understand what is going on much more clearly in the program. It is a binary search program that reads a .dat file of a list of presidents and sorts them alphabetically.…
-1
votes
1 answer

Implementing a nonrecursive preorder traversal method

I need to implement a preorder traversal method. Traversing a binary tree of nodes. Im trying to figure out a solution for the problem below. I know how to implement such a method, but the problem is that I can't deviate from the rules my teacher…
-1
votes
1 answer

Cannot traverse a binary tree with non-recursive inorder method

I am trying to traverse a binary tree built with the input data from keyboard. Data is inserted to the binary tree successfully. I have a switch statement, where 'case 3' should traverse (and print) the binary tree with non-recursive Inorder…
Basak Oguz
  • 17
  • 7
-1
votes
4 answers

Clojure multiply first n elements in sequence by 'x' non recursive

I am a newbie in clojure and came across a problem which says, multiply first n elements in a sequence by some number 'x' (non recursively). So for example (multiply-n-by-x [1 2 3 4 5] 2 10) => [10 20 30 4 5] So here i understood that i need to…
Harsh Shah
  • 368
  • 3
  • 17
-1
votes
2 answers

Recursive vs non-recursive

Possible Duplicate: Recursion and Iteration What is the difference between a recursive and a non-recursive function? Fibonacci to be exact. I looking for answers that relate towards the time and memory.
dalawh
  • 886
  • 8
  • 15
  • 37
-2
votes
1 answer

Iterative version of the Bron–Kerbosch algorithm with pivoting

I need much a correct pseudocode of Bron–Kerbosch algorithm (it enumerates all maximal cliques in an undirected unweighted graph). I need iterative (non-recursive) solution with a stack. And the version of the algorithm should be "with pivot" rather…
ttnphns
  • 137
  • 2
  • 14
-2
votes
1 answer

How to convert this recursive function into an iterative version?

This code basically computes nCr to print a pascal's triangle. #include int nCr(int n,int r){ if (r == 0 || r == n || n == 1 || n == 0){ return 1; } else{ return nCr(n-1,r) + nCr(n-1,r-1); } } How would this…
-2
votes
1 answer

optimizing a non recursive algorithm of an integer sequence

In an recruiting test platform , I had the following integer sequence problem that I solve it without a recursive function to avoid Stack Overflow : Here's a short description of the problem : We have a mark and at each stage we will move forward or…
Aminos
  • 754
  • 1
  • 20
  • 40
-2
votes
2 answers

Time and Space complexity of recursive and non-recursive small algorithm

Consider two functions that accept as a parameter an unsigned integer and returns the number of digits of this number. One function is recursive and the other is non-recursive. In terms of complexity , which implementation is better? The language…
-3
votes
1 answer

Quicksort non recursive

The statement says: Write a nonrecursive (negative) function which given a list of integers (possibly disordered) function returns the same list with negative numbers to positive head and back (regardless of the order between them). This algorithm…
David
  • 27
  • 1
  • 7
-4
votes
1 answer

How can I write a non recursive algorithm to add root to tree?

I need a non recursive algorithm that will add up the root to the tree values, and then display the value that is the highest. Not to add up every element in the tree, just the highest value way to get from root to leaf. 2 …
-4
votes
2 answers

generate all permutations with repetition....non-recursive in C

So I would like to know how to write a non-recursive function to print all permutations given an N and r where r^N gives you the total number of permutations. Example: N = 3, r = 2, total permutations =…
1 2 3 4 5 6 7
8