# Tagged Questions

The tag has no usage guidance.

1answer
101 views

### Handling the process of large-scale lists [closed]

What are the efficient ways to process huge lists (+10 millions), and things to consider while manipulating huge lists. First question, when should I use recursion, and when I shouldn't. In both ...
1answer
436 views

### Is it possible to apply Master Theorem for finding the square and cube root

I was asked to calculate the running time of an algorithm which finds the square root and cube root of a given number. Is it possible to apply Master theorem with regards to this? First, I need to ...
1answer
2k views

### how to enumerate/generate all possible binary trees from N leaves and N-1 nodes?

I am trying to implement the 24 Game in ansi C. This game goes as follows: For a list of four given numbers, try to find a solution involving these four numbers, that, using addition(+), subtraction(-...
1answer
380 views

### Do compilers un-inline recurrent expressions?

Does a compiler look for recurrent expressions to convert it into 'function' to reduce binary size and improve performance? Of course, the obvious answer might be "some do it, some don't", so I ask ...
3answers
10k views

### Find all possible subarrays of an Array

I am lost I just can't seem to get my head around backtracking/recursion approaches. I understand how simple recursion problems like factorials work I can even trace those by hand. But when it comes ...
1answer
210 views

### How to efficiently sort a recursively defined Stack?

I am trying to implement a recursively defined Stack and sort it in Java. I don't have a particular usage of this program in mind. I found this approach of stack implementation a bit useful while ...
4answers
211 views

### Wrap all external calls with flag to fight against recursion and double-entry?

Producing predictable output for each possible input is the responsibility of each module. For example (in C#): class Logger { public ITextWriter Writer { get; set; } private uint counter; ...
3answers
206 views

### What does this function do?

Does this function means its calculating x=(x-1) + x^2? Function unknown(x) if ( x == 1 ) return 1 else return unknown(x‐1) + x*x
1answer
291 views

### Best way to deal with Floors and Ceiling when using substitution method to solve Recurrences

I'm currently using substitution method to solve recurrences. The problem I'm having is dealing with T(n) that have either ceilings or floors. For example in the following example see example here. ...
2answers
185 views

### Is this looping solution possible with recursion?

Eventually, I would like to generalize this solutions to work with a Tuple of any length. I think recursion is required for that, but I haven't been able to do it. def combineRanges(maxValues) : ...
3answers
368 views

### How to convert this recursive problem to iterative? Line Simplification algorithm fails to run due to Maximum Recursion Depth being hit

I am implementing the Douglas, Peucker's Line Simplification algorithm in Python. I started with this implementation. However, it fails to run in Python due to Maximum Recursion Depth being hit. How ...
2answers
169 views

### General recursion to tail-recursion

Is it theoretically possible to transform every kind of general-recursion into tail-recursion? Are they equivalent for example from a lambda-calculus point of view? That's a debate between me and an ...
2answers
339 views

### Calling same method on different object - Recursion?

I have an object that contains a reference to another object of the same type. Example in PHP: class A { protected \$child; public function __construct(A \$child = null) { \$this->...
1answer
387 views

### How can I rewrite this linked-list manipulation as tail-recursive?

Given a liked list, I'd like to swap every pair of nodes as follows: input: a-b-c-d-e-f-g output: b-a-d-c-f-e-g If there's an odd number of nodes then the last node is tacked on as-is. This should ...
1answer
734 views

### Recursion VS memory allocation [duplicate]

Which approach is most popular in real-world examples: recursion or iteration? For example, simple tree preorder traversal with recursion: void preorderTraversal( Node root ){ if( root == null ) ...
3answers
8k views

### Are there advantages for using recursion over iteration - other than sometimes readability and elegance? [duplicate]

I am about to make two assumptions. Please correct me if they're wrong: There isn't a recursive algorithm without an iterative equivalent. Iteration is always cheaper performance-wise than recursion ...
3answers
124 views

### Is there any point in writing a random tester for code that deals with inductive data structures?

Let's say we're writing a simple JSON parser and we've fully covered the code with unit tests: it can parse primitives "0", "123", "-456", '""', '"asd"', true, false it can parse arrays "[]", "[1, 2,...
6answers
4k views

### Can recursion be done in parallel? Would that make sense?

Say, I am using a simple recursive algo for fibonacci , which would be executed as: fib(5) -> fib(4)+fib(3) | | fib(3)+fib(2)| fib(2)+fib(1) and so on Now,...
2answers
3k views

### Is recursive code slower than non-recursive code?

Now I'm only a novice programmer, but what my friends that are studying programming tell me is that recursive code is a good thing, it leads to less code duplication and it looks more elegant. Now ...
5answers
2k views

### What are the advantages of recursion compared to iteration? [duplicate]

I'm trying to understand when is preferred to use recursion rather than iteration. Actually I've encountered recursion only in Javascript but never in Python. I imagine that recursion should be used ...
1answer
3k views

### Utilising Promises, Closures and Recursion in Node.js

I have employed a recursive call to a closure in order to mitigate against some race conditions I am getting (That's what I think it is). I'd like to know if (and why) this is a good solution or a bad ...
1answer
240 views

### Designing software functions which are both pausable and restartable

Consider the following situation: One hardware device, two applications (1 C# application, 1 Firmware). The C# application sends frames to the firmware and the firmware executes scripts. C# -> ...
4answers
1k views

### Does the Composite design pattern implement recursive behavior?

The Composite design pattern allows us to call an operation() on a 'composite' node in a tree structure, and this operation() will be called on all of the children, subchildren and so on. When an ...
1answer
128 views

### Applying the Art Gallery problem to optimal sensor placement

I am trying to design an algorithm for optimal sensor placement in a given area. After doing some research I found the Art Gallery Problem. However, this problem assumes that the guards can see all ...
2answers
57 views

### Is array dependence on previous terms considered recursive?

For example, take the case of Fibonacci number to calculate nth number you require n-1 and n-2 term. If I do it with bottom up approach, is it recursion as f(n) depends on f(n-1)?
1answer
487 views

### Is this a good example of open recursion?

I understand open recursion as the process of a method on a class calling another method on a class using a keyword such as this, but whereby the method call may actually be bound to a sub class at ...
1answer
614 views

### How can Lisp produce an iterative process from a recursive procedure?

I am starting to learn Lisp, using the SICP book. The authors mention that a procedure (i.e. function) can be recursive or iterative. Additionally, the process those procedures will generate will also ...
1answer
56 views

### Verify 0 or 2+ sub sections in a section

There is a rule in writing: When you break a section into subsections, typically it should have more than one subsection. This goes back to the old high school composition rules: if you have an A. ...
2answers
1k views

### Can someone explain the concept behind Haskell's memoization?

(note I'm putting the question here because it's about the conceptual mechanics of it, rather than a coding problem) I was working on a small program, that was using a sequence of fibonacci numbers ...
1answer
150 views

### Better way to create samples

I've done this piece of code for creating bernulli samples, but I think that it is a so heavy algorithm because every time I call this recursive function I create a new vector that is passed to it. Is ...
1answer
611 views

### Find product using summation C# Problem? [closed]

I am trying to write a simple program to find the product of two numbers (X, Y) without using multiplication. Meaning that I will only use summation to find the product. I am trying to use the "...
4answers
1k views

### When there's no TCO, when to worry about blowing the stack?

Every single time there's a discussion about a new programming language targetting the JVM, there are inevitably people saying things like: "The JVM doesn't support tail-call optimization, so I ...
2answers
1k views

### Getting the relational table data into XML recursively

I have levels of tables (Level1, Level2, Level3, ...) For simplicity, we'll say I have 3 levels. The rows in the higher level tables are parents of lower level table rows. The relationship does not ...
1answer
217 views

### Trace code pascal [closed]

I haven't worked with Pascal so far, and my problem is understanding the recursive aspects that prm assignment operators and how the final (correct) value is derived. Would someone please explain that ...
1answer
3k views

### Tips for Tail Call Recursion in Python [duplicate]

Ok, Python doesn't have tail call optimization. But for those who think better recursively than "looply", whats the best practices to write code?? 1000 stack calls are enough for many cases, but ...
1answer
1k views

### Having trouble understanding recursion [duplicate]

I have just started learning about recursion but I'm having a hard time understanding it. Please would you recommend any links or books that explain recursion in detail.
2answers
1k views

### Can and do compilers convert recursive logic to equivalent non-recursive logic?

I've been learning F# and it's starting to influence how I think when I'm programming C#. To that end, I have been using recursion when I feel the result improves readability and I can't envision it ...
2answers
13k views

### Reason for return statement in recursive function call

I just had a doubt in my mind. The following subroutine(to search an element, in a list, for example) has a return statement at the end: list *search_list(list *l, item_type x) { if (l == NULL) ...
1answer
500 views

### Decrement operator difference between C++ and Java? [closed]

Please tell me why the same piece of code behaves differently in C++ and JAVA. Ok first I implement a function to calculate the factorial of an Int RECURSIVELY In JAVA: int f(int x) { ...
8answers
26k views

### What methods are there to avoid a stack overflow in a recursive algorithm?

Question What are the possible ways to solve a stack overflow caused by an recursive algorithm? Example I'm trying to solve Project Euler problem 14 and decided to try it with a recursive algorithm....
1answer
210 views

### Course Map Generator

My university lists the rotation of courses each semester/year. Therefore, it is possible to predict when every class will be taught. I am trying to create a JavaScript (language is irrelevant, ...
3answers
1k views

### Designing a self-describing JSON document system

I'm trying to devise a document system for a specific domain involving simple objects (People, Companies, Invoices, etc.) that would also be able to completely describe itself. This self-description ...
3answers
3k views

### How many are too many nested function calls?

Quoted from MSDN about StackOverflowException: The exception that is thrown when the execution stack overflows because it contains too many nested method calls. Too many is pretty vague here. ...
1answer
9k views

### What does “recursive” mean for a program which processes files and directories?

I know what recursion is in programming. I do understand the basics of version control systems (have used svn that is). But I have often wondered what the meaning of "recursion" or "recursive" is ...
1answer
609 views

### Is this an example of recursion?

I am implementing inheritance of something called Contexts. Each Context holds a link to its parent context. If that Context is the root Context, its parent is null. In order to walk up the ...
8answers
34k views

### Recursion or while loops

I was reading about some development interview practices, specifically about the technical questions and tests asked at interviews and I've stumbled quite a few times over sayings of the genre "Ok you ...
5answers
4k views

### What is the difference between “recursion” and “self-reference”?

The wikipedia articles are too advanced for me to understand, could someone give me a simple explanation please?
4answers
11k views

### Finding the time complexity of the following program that uses recursion

I need to find the time complexity in terms of Big Oh notation for the following program which computes the factorial of a given number: The program goes like this: public int fact(int n){ if (n &...
2answers
1k views

### Y combinator and tail call optimizations

The definition of a Y combinator in F# is let rec y f x = f (y f) x f expects to have as a first argument some continuation for the recursive subproblems. Using the y f as a continuation, we see ...
4answers
5k views

### Is there a way to display the stack during recursion method?

I'm trying to learn recursion. I copied this bit of code from my book and added the displays to help me trace what the method is doing and when. public static void main(String[] args) { ...