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
12 views
clojure - finding first match in recursive search
I am searching a recursive solution space and would like to return the first match I find. (I am using this to solve sudoku, but I guess this would apply to any recursively defined problem or ...
1
vote
1answer
32 views
Recursive java.util.Properties references
Background
A subclass of java.util.Properties attempts to recursively resolve configured properties:
prop_a=Prop A is ${prop_b}
prop_b=Prop B is ${prop_c}
prop_c=Prop C.
After reading the file, ...
-1
votes
0answers
28 views
How do I implement a recursive N-body algorithm in C++? [closed]
I have moving spheres within a 3D cube and I am trying to implement an N-Body algorithm using recursion. The following image is a review of the algorithm I'm trying to implement. The basic idea is to ...
1
vote
1answer
62 views
List-flattening function in erlang feels too wordy
I wrote a tail-recursive list-flattening function, but I'm not too happy with it.
a) Is tail-recursion necessary here, or will the function be optimized without it?
b) It's ugly how many clauses ...
0
votes
1answer
39 views
Creating an Array of Linked Lists from a BST
Question
Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists)
Here is my ...
4
votes
1answer
48 views
Recursive XML2JSON parser
I made a Python function that takes an XML file as a parameter and returns a JSON.
My goal is to convert some XML get from an old API to convert into Restful API.
This function works, but it is ...
2
votes
1answer
33 views
Efficiency of Recursive Checkers Legal Move Generator
I'm implementing a checkers engine for a scientific experiment. I found out through profiling that this is one of the functions that takes up a lot of time. I'm not looking for an in-depth analysis, ...
5
votes
1answer
79 views
Is there a better way to walk a directory tree?
I just started to learn Haskell, and i wrote a function that walks the directory tree recursively and pass the content of each directory to a callback function:
The content of the directory is a ...
2
votes
2answers
58 views
multi-recursive replacement function
I wrote a function for creating all possible translations of a source string, based on a multiple translation map. It works, but generates a lot of intermediate maps (see line marked with *). Is there ...
1
vote
0answers
30 views
PostgreSQL: Get all recursive dependencies of a single database object
I've written a SELECT statement that creates a List of all objects that depend on a single object, so that if I wanted to DROP that object I could DROP all referenced objects first without using ...
2
votes
1answer
51 views
Avoiding use of an initialized variable that will either be changed or ignored
Follow on from this question
This is a follow on question from one I asked a few days ago. I am making (or rather have made) a recursive method that takes a list of ArrayList objects as its ...
3
votes
3answers
160 views
Trying to make recursive code designed to find objects with even references tidier
As the title says, I'm trying to make my code less horrible looking! For a university practical, I've to use recursive methods to return the even references in a collection of Integer objects stored ...
2
votes
1answer
69 views
Javascript “recursion” via setTimeout
I understand that because of Javascript's single-threaded execution, long loops or recursive calls could make the browser unresponsive while they execute.
I thought about simulating recursion using ...
1
vote
3answers
55 views
How to improve this functional python fast exponentiation routine?
I have the following python functions for exponentiation by squaring :
def rep_square(b,exp):
return reduce(lambda sq,i: sq + [sq[-1]*sq[-1]],xrange(len(radix(exp,2))),[b])
def ...
2
votes
1answer
129 views
Recursion and iteration how can i optimize this code
I have written some code which will fetch contents from a resource which is actually stored in a tree format. Since it is in a tree format, there will be a parent-child relation and hence recursion.
...
1
vote
1answer
100 views
Code review for recursion to map phone number to strings
I am trying to solve the following via recursion: In a phone we have each digit mapped to a number.
Example:
1 2(ABC) 3(DEF)
4(GHI) 5(JKL) 6(MNO)
7(PRS) 8(TUV) 9(XYZ)
* 0 ...
3
votes
2answers
77 views
JQuery typed wrapper in C#; possible recursion
I am writing an object in C# to mimic jQuery's various functions. That is, calling the constructor is akin to calling the $() function of jQuery. For example,
var a = new JQuery("div").eq(0);
...
2
votes
1answer
70 views
How to rewrite recursion in a more ruby way
def get_all_friends(uid, client)
friends = client.friendships.friends(uid: uid)
total = friends.total_number
get_friends(total, 0, uid, client)
end
def get_friends(total, cursor, uid, client)
...
2
votes
1answer
72 views
Which of these two paren-matching functions is better?
I am currently trying to learn Haskell (after taking a Scala course on Coursera); but while I can write functions that do what I want, I worry that I am not learning to write idomatic/clean/performant ...
4
votes
4answers
207 views
What do you think of my Recursive FizzBuzz?
I wanted to see if I fully understood recursion so I attempted the FizzBuzz challenge and applied recursion to it.
Did I do it correctly? Is this good code? Is there a more efficient way of doing ...
3
votes
1answer
84 views
Haskell tips/why doesnt this scale linearly?
My friend wrote a program which compares random arrangements of die faces to find the one with the most evenly distributed faces - especially when the faces are not a mere sequence.
I translated his ...
-1
votes
1answer
69 views
recursive function [closed]
I want to generate a random number then to check if it is in the database. If not then redo it.
My pseudo code:
PIN = GenerateRandomNumber().ToString();
...
1
vote
0answers
104 views
Print all interleavings of given two strings
Given two strings str1 and str2, write a function that prints all
interleavings of the given two strings. You may assume that all
characters in both strings are different
Example:
Input: ...
4
votes
0answers
422 views
Print all permutations with repetition of characters
Given a string of length n, print all permutation of the given string.
Repetition of characters is allowed. Print these permutations in
lexicographically sorted order
Examples:
Input: AB
...
2
votes
1answer
128 views
Scala: tail-recursive factorial
Is there anything what could be improved on this code?
def factorial(n: Int, offset: Int = 1): Int = {
if(n == 0) offset else factorial(n - 1, (offset * n))
}
The idea is to have tail-recursive ...
5
votes
2answers
525 views
pascal triangle in php (anything wrong with this solution?)
I saw that one of the interview questions could be building a pascal triangle.
Is there anything wrong with this particular solution I came up with?
function pascal_r($r){
$local = array();
...
0
votes
1answer
109 views
Codechef: Byte Landian Gold Coin - Java [closed]
This is the link to the question.
http://www.codechef.com/problems/COINS
Not sure what is wrong with this code. These are the input/output that I get
12 --> 13
13 --> 16
When I submit it to ...
1
vote
2answers
151 views
Confusing program for reversing link List using recursion? [closed]
I was trying to reverse the link list using recursion and somehow I did it?
But one think is bothering me how the head in the last line finally points to the element 4 (i.e. the first element after ...
2
votes
2answers
189 views
simple stupid F# async telnet client
Did I write this code to correctly be tail call optimized? Am I forcing computations more than I need with !? Did I generally write this asynchronously correctly to allow sends and receives to occur ...
1
vote
1answer
313 views
shortest path recursive algorithm [closed]
This is the first time I come to this site, even though I tried to post in Stack Overflow but was told that this would be a better place to ask. So I hope this is the right place for my question.
...
2
votes
2answers
105 views
Finding if value exists in any column recursively
Could you please review if I've done this correctly? Our company uses old version of JAXB so it does not allow generics. Other than that, I am using recursive calls because Rows can have subrows and I ...
1
vote
2answers
184 views
Need a method that recursively finds all objects of type System.Web.UI.Pair in an object array
I have an object array that contains various types of objects (primitives, strings, other object arrays) at arbitrary levels of nesting. I need to pull all objects of type System.Web.UI.Pair from ...
0
votes
1answer
191 views
recursion using pipes
So hi,
my goal with my code is to have a program similar to pipes in unix like
$printenv | sort | less
using recursion. I'm pretty new to pipes and file descriptor manipulation so I don't know ...
0
votes
0answers
197 views
Code Improvement on generating Tree Structure
I'm using actionscript/flex 4.5
I have a Class (DEF) with three main properties
COD_CLASSE is the ID of the object
COD_CLASSE_PADRE is the ID of the parent of the object
children is an ...
3
votes
0answers
167 views
Building an ASP.NET Menu Recursively - Needs Refactoring and Readability Improving
The following code builds an ASP.NET menu recursively from data in a database:
Imports Microsoft.VisualBasic
Public Class MenuBarHelper
Public Shared Function GetMainMenu() As Menu
Dim ...
2
votes
4answers
321 views
How can I remove unwanted combinations from my algorithm in C#?
I have written an algorithm in C#. It is recursive, but it is not optimal. Maybe you have suggestions for improvement? (I already posted this question on stackoverflow but the question was closed ...
0
votes
0answers
116 views
Ruby Trie Iterative to_a
I've been benchmarking recursive and iterative ruby trie functions. Unsurprisingly the iterative functions seem perform better then my recursive implementations. The only exception to this is my to_a. ...
3
votes
2answers
147 views
Haskell recursions, level zero
As a learning process I created 'reverse' function in a few different ways. Tinkering with 'reverse' made currying, folds and other stuff easier to understand. Almost natural!
I know these are ...
0
votes
2answers
4k views
Create a list of all possible combinations of elements into n-groups from a set of size k
I'm trying to write a Java program that, given a particular number of groups and number of total participants, creates a list of all possible ways to fill that number of groups evenly using all the ...
3
votes
3answers
362 views
Ruby fibonacci(n) recursive computation optimized with reflection. Is this good Ruby?
I'm coming from Java and this is my first attempt with Ruby reflection.
The idea is to take the common-known (and awfully bad performing) fibonacci(n) recursive method:
# recursively computate ...
2
votes
2answers
442 views
Code review of Pouring water from code chef using Scala
I had posted this question on Stackoverflow and it seems like code review might be a better venue for my query. My question is as follows:
I am trying to solve the pouring water problem from codechef ...
3
votes
1answer
297 views
How to avoid unchecked cast warning in my generic recursive Iterator in Java
Somewhat odd that Java's collection framework has no iterator for recursive data structures... Since I needed something like this, I wrote my own. First of I need recursive elements:
public interface ...