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

0
votes
1answer
22 views

Project Euler problem 31 - tail recursive algorithm

In Scala, a recursive algorithm for project Euler problem 31 is the following: ...
6
votes
2answers
109 views

Infix to postfix conversion

I have written a C++ program to convert an infix expression to postfix expression using recursion. I would like to know if it can be improved if possible. Can we improve it by not using a stack? I am ...
4
votes
1answer
50 views

Seeking improved Objective-C permutation algorithm

This algorithm seeks to find all of the possible permutations of a word: ...
3
votes
1answer
44 views

Generating all keypad possibilities

I ran into this question on Stack Overflow. It looked like a really cool thing to try myself, being that I haven't done any recursion for ages (read at least 2 years). ...
1
vote
0answers
22 views

Optimizing Recursive Quadtree

I have a written a quadtree program in Python 2.7 to cross-correlate large catalogs with each other i.e. find the common objects in the catalogs based on their position. The problem is that it's still ...
0
votes
0answers
35 views

How to avoid StackOverflowError caused by the number of recursion calls in Java? [closed]

I want to solve this problem: https://www.hackerrank.com/challenges/find-median ,i.e. find the median element in unsorted array. To do this I perform quickselect algorithm. My program works correctly ...
3
votes
1answer
68 views

Finding if there is a subset that sums to a target value from an array of integers

I came across this problem. Problem Statement: Given an array of ints, is it possible to choose a group of some of the ...
1
vote
1answer
37 views

improve performance of recursive function in c# method

I'm trying to write a function which will cache objects in memory. The function below works, but performance is unbearable. What would you recommend to improve performance? ...
-2
votes
1answer
50 views

hailstone sequence using recursion in python

Douglas Hofstadter's Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle: Pick a positive integer n as the start. If n is even, divide it by 2. If n is ...
10
votes
3answers
326 views

List all possible numbers from a given array that sums up to a given number

I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value. Example: Input: array = {1, 2, ...
4
votes
0answers
49 views

Fibonacci number function: convert to tail-recursion?

I've been implementing a function for calculating the nth Fibonacci number in F#. So far the best implementation I could come up with is this: ...
1
vote
1answer
55 views

Solving the coin change algorithm using 10 coins

I'm solving the coin change problem having target of n and upper bound as n. Also the maximum number of coins is 10. For example. if the target is 11. then the possible outcomes are - ...
2
votes
1answer
82 views

Modifying nested dictionaries in Python

My task was to take a configuration specified as a dictionary and run some function with it (the actual function is not relevant here). After implementing that, I was asked to allow some "sweeping" of ...
5
votes
3answers
341 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
611 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
42 views
8
votes
3answers
154 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
32 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
851 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
11 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
54 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
54 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
57 views

Optimization of matrix determinant calculation

I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach: ...
2
votes
1answer
41 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
62 views

Recursive flatten with lazy evaluation iterator

I'm trying to rewrite this: ...
3
votes
2answers
61 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. ...
3
votes
2answers
63 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
155 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
321 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
272 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
64 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
420 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
101 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
620 views
2
votes
2answers
80 views

Recursive function for listing directories [closed]

The below code is recursive function that list directories in 2 levels: ...
3
votes
1answer
155 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
122 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
113 views

Linked List reversal

Recursive version. The only interesting function: The original version: ...
6
votes
1answer
135 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
335 views

Validating that all open/close parentheses are correctly matched

It returns true for: a*(b+c) ()() (()) ((!!(123(x)))) and returns false for: ...
10
votes
2answers
127 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
335 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
80 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
19 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
334 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
828 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
132 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
211 views

Constraint Programming: Map color problem

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
606 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 ...