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
1answer
23 views
Assign value of nested array as array key
I have a multi dimensional array like this:
[0] =>
['batch_id'] => '1'
['some_stuff'] => 'values'
[0] =>
['unit_id'] => '12'
['some_stuff'] => 'values'
...
-1
votes
0answers
36 views
What is so specific about reentrancy? [closed]
(the question was closed at Quality Assurance though I do not understand how it may be no related to that)
Developers are obsessed with ensuring (or avoiding) the reentrancy when it regards to ...
1
vote
1answer
36 views
Recursive Determinant
The following code I devised to compute a determinant:
module MatrixOps where
determinant :: (Num a, Fractional a) => [[a]] -> a
determinant [[x]] = x
determinant mat =
sum [s*x*(determinant ...
1
vote
1answer
38 views
Pascal's Triangle in Javascript
Here's the problem statement:
Given an integer value, print out Pascal's Triangle to the corresponding depth in row-major format:
Input Sample:
6
Output Sample:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 ...
1
vote
1answer
37 views
Improve file-path finding method
I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: {'Tkinter.py': 'C:\Python27\Lib\lib-tk\Tkinter.py', ...}.
I am using this in a ...
2
votes
0answers
34 views
functional javascript - recursively walking a tree to build up a new one; could this be better factored as a reduce?
/**
* recursively build a nested Backbone.Model or Backbone.Collection
* from a deep JSON structure.
*
* undefined for regex values
*/
exports.modelify = function modelify (data) {
if ...
1
vote
2answers
38 views
Recursively print in scala
I have just picked up Scala like 2 hours ago, and I am thinking of printing a series like 1 to 10 but in a recursive fashion. I do not understand what is wrong with this:
def printSeries(x:Int):Int = ...
2
votes
2answers
101 views
How can I optimize this recursive function?
I have a function that I need to optimize:
def search(graph, node, maxdepth = 10, depth = 0):
nodes = []
for neighbor in graph.neighbors_iter(node):
if ...
-2
votes
1answer
59 views
whats wrong with my recursion? [closed]
I am working on trying to create a tree in a recursive fashion. I have gotten constructive feedback on my previous questions so I try once more. I dont want to use malloc, and please dont post ...
2
votes
1answer
59 views
Iterative Collatz with memoization
I'm trying to write efficient code for calculating the chain-length of each number.
For example, 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1.
It took 13 iterations ...
2
votes
2answers
55 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
40 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
vote
1answer
64 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
48 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
2answers
61 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 ...