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.
0
votes
1answer
51 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 ...
10
votes
1answer
139 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
82 views
2
votes
2answers
48 views
Recursive function for listing directories [closed]
The below code is recursive function that list directories in 2 levels:
...
3
votes
1answer
58 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
101 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
96 views
6
votes
1answer
95 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
164 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))
...
9
votes
2answers
89 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
73 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
71 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
16 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
215 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 ?
...
7
votes
5answers
722 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
110 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
148 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
391 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
76 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
409 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
155 views
0
votes
1answer
119 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
54 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
179 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
282 views
6
votes
2answers
353 views
2
votes
2answers
70 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
87 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
209 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
333 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
106 views
4
votes
2answers
117 views
Numeric expression parser - calculator
In particular, if someone could describe a better way to go from the tokenized list to the Expression tree, it would be super helpful. I would like to get rid of the casting in the parser but am not ...
12
votes
5answers
1k views
Identifying first negative number in array of doubles
I was asked to create a function that checks if an array of doubles has all negative numbers or none. If these 2 (all negative, all positive) are false, check the ...
6
votes
1answer
283 views
Tower of Hanoi solver
Requesting code review, best practices, optimizations for this solution to the Tower of Hanoi problem.
...
2
votes
3answers
158 views
To check if a string C is an interleaving of A and B Code
This is my code to check if a string C is an interleaving of Strings A and B. Please suggests optimizations, and where I can improve.
...
14
votes
4answers
741 views
Displaying each number of an integer in a sequence
One of the books I'm currently reading to learn C# asked me to write a method that takes an integer between 1 and 99999 and displays each number in that integer in a sequence, separating each digit by ...
0
votes
2answers
39 views
Generic sequence splitter in Common Lisp
I wrote a function split-seq-by-n which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the ...
11
votes
6answers
588 views
Help refactor this to be less procedural and more recursive
Reference: Is this a faithful rendition of the selection sort algorithm?
I'm working through an elementary book on sort and search algorithms, and writing some sample code to test my understanding. ...
7
votes
2answers
207 views
Is this non-recursive mergesort efficient and a good way to simulate the recursive version?
My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are:
...
5
votes
2answers
141 views
Optimize disk enumeration and file listing
I am writing C++ code to enumerate whole HDD and drive listing. However, it takes more than 15 minutes to complete the disk enumeration of all drives (HDD capacity 500GB) and compile the response in ...
2
votes
3answers
114 views
Python script to touch files of a particular pattern in all folders of a given name
The intent of this script is to hunt down all "*/testResults/*.xml" files and touch them, so that our build system doesn't issue errors that the files are too old ...
4
votes
1answer
50 views
Good OCaml style
I wanted to write a small but non-trivial function in OCaml to test my understanding. I have only a basic understanding of the libraries, and no idea at all of what is considered good style. The ...
5
votes
3answers
104 views
Pair matching elements from two lists
Here is a method that takes two lists (l1 and l2) and pairs up elements that "match". As you can see at the end of the code ...
5
votes
2answers
101 views
Recursive reverse function
Write a recursive version of the function reverse(s), which reverses the string s in place.
Here is my solution:
...
8
votes
3answers
224 views
Integer-to-string conversion using recursion
Adapt the ideas of printd to write recursive version of itoa; that is, convert integer into a string by calling a recursive ...
-1
votes
1answer
81 views
Recursively calculating powers of numbers [closed]
In this program, I understood everything except power(x1,y1-1). I want to know how the power(x1,y1-1) function exactly works.
...
1
vote
1answer
48 views
replacing explicit recursion with a fold
as an exercise I wanted to rewrite this toy python code in haskell.
...
7
votes
1answer
146 views
Suggestions needed for alternative methods of solving sudoku
I am new to programming as well as this site. I am learning Java as my first programming language. I have written a bit of code (of course after struggling a lot). I would love to read expert reviews ...
0
votes
0answers
77 views
REST Response: Checking for Success and Error
I thought this was pretty slick - maybe not, I just wanted to share and maybe get some feedback:
As part of a REST client class:
Accepts the JSON response from REST or REST-like service, searches ...
3
votes
3answers
645 views
Reversing a string in-place - recursion or iteration?
I am practicing my recursion skills as I think I am really weak in this area.
I have written the following Java class whose purpose is to reverse a string but to do it 'in-place' - i.e. no additional ...