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

8
votes
1answer
115 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 ...
5
votes
1answer
69 views
2
votes
2answers
47 views

Recursive function for listing directories [closed]

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

Linked List reversal

Recursive version. The only interesting function: The original version: ...
6
votes
2answers
83 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
157 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
87 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
69 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
203 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
715 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
109 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
142 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
361 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
407 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
153 views
0
votes
1answer
115 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
53 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
163 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
275 views

QuickSort of Comparable[]

Here is the code for the QuickSort class that I created. ...
2
votes
2answers
68 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
193 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
313 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
103 views

Iteration to recursive function

In my first iterative algorithm, I do this ...
4
votes
2answers
110 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
269 views

Tower of Hanoi solver

Requesting code review, best practices, optimizations for this solution to the Tower of Hanoi problem. ...
2
votes
3answers
147 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
715 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
38 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
587 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
203 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
138 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
107 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
103 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
98 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
211 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
78 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
144 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
73 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
586 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 ...
4
votes
1answer
80 views

Using a function recursively to calculate higher-order derivatives

I am writing a code to do some numerical task using the routines of Numerical Recipes book. One of my objectives is to calculate the second derivative of a function and I have a routine that ...