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.
1
vote
0answers
20 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
32 views
How to avoid StackOverflowError caused by the number of recursion calls in Java? [on hold]
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 ...
1
vote
1answer
33 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
0answers
37 views
path in a labyrinth [closed]
i have an algorithm in path in a labyrinth can you help me solve this problem ? I have a problem in my instructor during our discussion
here is the algorithm
- Let the current position in the ...
-2
votes
1answer
49 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
320 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
44 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
51 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
80 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
338 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
610 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
150 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
847 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
53 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
51 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
61 views
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.
...
3
votes
2answers
59 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
151 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
317 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
271 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
388 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
617 views
2
votes
2answers
77 views
Recursive function for listing directories [closed]
The below code is recursive function that list directories in 2 levels:
...
3
votes
1answer
150 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
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
304 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
123 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
313 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
18 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
327 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
827 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
197 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
596 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
108 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
421 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
195 views
0
votes
1answer
197 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 ...