Recursion in computer science is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem.

learn more… | top users | synonyms

5
votes
3answers
324 views

Making this Tic Tac Toe implementation more recursive

Here is a Tic Tac Toe game in C++ that I have been working on. My questions are as follows: I tested it for bugs, but if you find any, please post the solution! I want to make the code more ...
9
votes
4answers
592 views

Recursive implementation of palindrome string checker - refactoring issue

I've tried to refactor my program to single return statement at the end of the program however it ruins the end statements of the recursion. because I want to return from function in specific line and ...
1
vote
1answer
37 views
4
votes
0answers
33 views

Travelling Salesman in Qt

I am writing a recursive function based on the Travelling Salesman Problem. Is this a correct way of doing things, or am I creating memory leaks? Prerequisites are: a two dimensional matrix ...
2
votes
1answer
28 views

Optimizing string replacement program that uses recursion

I have the following string replacement program for a string of size 256: I am replacing the string "\'" with the string ' Please suggest any modifications if needed or any ...
5
votes
6answers
839 views

Get rid of recursion in fruit picker

I have this simple code and it is working fine it is self explanatory: the user will choose a random number 10 times and based on the random number the array will be filled by fruits. ...
0
votes
0answers
10 views

performance in javascript recursion [duplicate]

I have this simple code and it is working fine It is self explanatory: the user will choose a random number 10 times and based on therandom number the array will be filled by fruits. ...
2
votes
1answer
50 views

Retaining depth information and recursive traversals

I have been using the pattern below for some time and it has worked well, but more than once I have almost bled my brain out of my ear trying to keep track of: the recursion depth the recursion path ...
4
votes
1answer
49 views

Recursively searching the Windows Registry

This function is part of a the Registry class that can be found on Google Drive. The class was originally written by Steve McMahon for VB6, but I ported it to VBA ...
2
votes
1answer
29 views

Multiplying a numeric string with the “vedic method”

This is vedic method multiplication. This code takes time on a very long numeric string, and I want to optimize it. I also apply recursion on multIndices (this ...
4
votes
1answer
54 views

Optimization of matrix determinant calculation

I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach: ...
2
votes
1answer
39 views

Python script to find large folders

I wrote this script a few days ago to find all files which were taking up over a certain threshold of memory on the hard drive. A hard drive on one of my computers had just 6 GB left, so I needed to ...
4
votes
2answers
59 views

Recursive flatten with lazy evaluation iterator

I'm trying to rewrite this: ...
3
votes
2answers
58 views

Optimizing a recursion code over lists

I'm writing three functions which iterate over lists, I want do this recursively, but I think this code is not as efficient as it could be. ...
2
votes
2answers
49 views

How might we make this Python Merge Sort implementation more Pythonic?

I've implemented a (version of) Merge Sort algorithm in Python. My goal here is two-fold: Improve understanding of Merge Sort and recursion in a language agnostic way. Improve understanding of ...
3
votes
2answers
141 views

Pascal triangle algorithm is good but fails

I have created a function which returns the number that corresponds to the given row and column from the pascal triangle. I have used the formula for this: n! / r! * (r-n)! The code: ...
10
votes
2answers
299 views

Recursive maze solver

Up for review today is some C++11 code to recursively search a maze for a path to a specified goal. This one shows dead-ends it explored on the way to finding the solution. ...
5
votes
2answers
263 views

Can I simplify this recursive grid search?

I've written a recursive method for fetching grid neighbours in a symmetrical 2-dimensional grid, the problem is that I've found myself duplicating the code more or less into an overload to prevent my ...
0
votes
1answer
63 views

Understand recursion

I'm trying to improve my understanding of recursive and iterative processes. I've started with SICP, but have branched off to try and find a few exercises when I started having difficulty. Currently ...
11
votes
1answer
301 views

Recursion vs iteration of tree structure

Some recursive code is part of a particularly slow path of a project. Out of curiosity I was playing around with reimplementing the code using stack context iteration instead of recursion. Below are ...
7
votes
1answer
99 views

Speeding up subset sum implementation

Important fact: the number of the input is greater than 1. How do I use this fact to speed up this solution? ...
9
votes
4answers
596 views
2
votes
2answers
70 views

Recursive function for listing directories [closed]

The below code is recursive function that list directories in 2 levels: ...
3
votes
1answer
116 views

Recursively reading a directory in node.js

I made a function for recursively reading a directory and it just seems kind of long and complicated. If you could take a look and tell me what's good or bad about it, that would be great. Reading ...
3
votes
2answers
119 views

Recursive uniform cost search that needs to be optimized

I have this uniform cost search that I created to solve Project Euler Questions 18 and 67. It takes the numbers in the txt file, places them into a two dimensional list, and then traverses them in a ...
7
votes
1answer
105 views

Linked List reversal

Recursive version. The only interesting function: The original version: ...
6
votes
1answer
128 views

Ray Tracer main loop

For the past week I have been studying and improving a ray tracer that I ported from JavaScript. The bare finished port was only exactly what was written in JavaScript and rendered at around 20fps at ...
4
votes
5answers
256 views

Validating that all Open/Close Parentheses are correctly matched

It returns true for: a*(b+c) ()() (()) ((!!(123(x)))) and returns false for (a((b+c)) )()( ))(( (rsd+3)*(-3-a)) ...
10
votes
2answers
116 views

Printing permutations of a given string

I want some feedback on the program I developed in C for printing the permutations of a given string. ...
5
votes
1answer
232 views

recursive function : filtering large multidimensional array by key element to HTML list

I have a multidimensional array as a result from a webservice called from PHP. I cannot edit the webservice, but the result is as ...
4
votes
1answer
79 views

Is recursion like this safe with a task queue on GAE?

I've written a function to call with the deferred library to generate a large task queue, and at first without the recursion it timed out (deadlineexceeded) so now I'm trying with a recursion but is ...
2
votes
0answers
17 views

Completing a Graph in Scheme

For the record, this is part of a homework assignment, but I have already implemented a solution. I am simply wondering if there is a better way to do it. Background: I am asked to write a procedure, ...
9
votes
3answers
305 views

Recursive Fibonacci with Generic delegates

Here is fast recursive fibonacci like for loop. How it be more readable and is possible remove TArg's ? ...
8
votes
5answers
811 views

Efficient pathfinding without heuristics?

Part of my program is a variable-sized set of Star Systems randomly linked by Warp Points. I have an A* algorithm working rather well in the grid, but the random warp point links mean that even though ...
8
votes
2answers
129 views

Finding path in Maze

I recently gave an interview and was asked the following question. I posted this here Finding path in Maze also, and someone suggested I should try Code Review. So here it goes. A maze is a group of ...
5
votes
2answers
185 views

Map color problem: Optimize using a heap?

I've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and ...
12
votes
3answers
549 views

Improving knapsack branch and bound: how to forward filter?

I've coded branch and bound to solve the knapsack problem, and use a greedy linear relaxation to find an upper bound on a node I'm currently exploring. What I mean by this is that I first sort the ...
6
votes
1answer
98 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
7
votes
2answers
420 views

Can this recursive binary search in C be made more concise?

Can someone please let me know if they see glaring issues with this code? I tested a handful of cases and it seems to work but in other threads. I often see much more concisely written versions of ...
4
votes
2answers
188 views
0
votes
1answer
182 views

Solving a Recursive method with Mazes [closed]

Given any map such as the one below, 1 for path and 0 for walls, can you guys review my code and see what I am doing wrong. My code is supposed to return an arrayList of the positions that it passed ...
0
votes
1answer
65 views

Solving a Recursive Maze method [closed]

Given any map such as the one below, 1 for path and 0 for walls, can you guys review my code and see what I am doing wrong. My code is supposed to return an arrayList of the positions that it passed ...
7
votes
1answer
330 views

Web service proxy that switches endpoint URLs in the event of a TimeoutException

I am creating a service (FaultTolerantCommunication) that wraps a call to a (web) service. Its responsibility is to switch the endpoint URL in the event of a ...
5
votes
2answers
365 views

QuickSort of Comparable[]

Here is the code for the QuickSort class that I created. ...
2
votes
2answers
104 views

Algorithms for traversing unordered tree

I have been doing some programming 'exercises'. I'm trying to come up with the most efficient algorithm for tree traversal. Consider the following function signature: ...
11
votes
1answer
125 views

Recursive calculator in C

This is a calculator I wrote for a student's project. It still has a problem (one that I know of), where it can't handle inputs of the form 2*2*2... (more than one ...
1
vote
3answers
258 views

Lowest common ancestor in recursive tree traversal

LCA = Lowest Common Ancestor The following code finds the lowest common ancestor in tree of nodes, where a node can have two parents, left and right. The tree looks like this: ...
9
votes
2answers
727 views

Math expression solver

Recently I've stumbled upon an interesting challenge for me. You should develop C application, that solves math expressions. Operations such as (+,-,*,/) should be supported, as well as (cos, sin, ...
6
votes
3answers
116 views

Iteration to recursive function

In my first iterative algorithm, I do this ...