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

0
votes
0answers
15 views

Directory listing in Node.JS

This solution works, and I like having all the logic after the return. The main purpose of this function was for use with other functions to return a file list: ...
0
votes
2answers
62 views

google foo.bar max path algorithm puzzle optimization [closed]

I got a programming puzzle described as follows: Save Beta Rabbit Oh no! The mad Professor Boolean has trapped Beta Rabbit in an NxN grid of rooms. In the center of each room (except for ...
2
votes
0answers
46 views

Calculate the arclength

I am trying to estimate a good approximation for \$\sqrt{1-x^2}\$ for \$x \in [0, 1]\$. I did this using a Bezièr curve, and made it so that the area under the two curves are alike. In order to ...
1
vote
0answers
17 views

Recursively walk directories with a callback function

This code works, but I want to refine it: ...
1
vote
1answer
52 views

Reverse a linked list recursively

This recursive calls reverseList on each node of the linked list. When returned from the function call, it changes the next link to the previous node. ...
1
vote
1answer
92 views

AI Tetris-like game

I was thinking to rewrite my Python code to C++ since it contains quite a lot of simple loops. I was stunned to find out that this critical part of code (the code below) is about 5 times slower than ...
1
vote
1answer
48 views

Storing hierarchical data into a data structure

With the following data in a table, ...
0
votes
1answer
62 views

Shell command line program

I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
1
vote
2answers
26 views

Finding all non-empty directories and their files on an SFTP server with Paramiko

The purpose of the following function is to find all non-empty directories, and the files in those non-empty directories. It recursively checks each directory on an SFTP server to see if it has any ...
2
votes
1answer
87 views

Searching a maze using DFS in C++

I have started learning recursion and search algorithms, especially DFS and BFS. In this program, I have tried to make an implementation of a maze-solving algorithm using DFS. The program is working ...
1
vote
0answers
44 views

Searching a Maze Using DFS [closed]

I am new to recursion and searching algorithms and am trying to implement a maze searching program using DFS. I have tried troubleshooting the issue, but there seems to be an error with my code. Any ...
-1
votes
1answer
41 views

Finding Sylvester sequence code

I've written this code to calculate the Sylvester sequence, which is defined as $$s_n = s_{n-1}(s_{n-1}-1)+1$$ where \$s_0=2\$. ...
0
votes
1answer
30 views

Get properties from all children in a recursive SQL structure

In our product, Company is a model that can have many Companies belonging to it; so some Companies are parents, some are children, and many are both. We have a ...
2
votes
1answer
27 views

Get all combination of a nested object with arbitrary levels

I have a JSON data which can be an object/array of recursively nested object or array. The value of an array can not be null, but an value in a object can be null. I would like to return all ...
3
votes
1answer
26 views

Get all combination of a nested object

I have JSON data which can be an object/array of recursively nested object or array. The value of an array can not be null, but a value in an object can be null. And I would like to return all ...
2
votes
2answers
40 views

Remove all occurrences of a digit from a number

I need to remove all occurrences of a digit from a number in a recursive function with this prototype: unsigned rem(unsigned num, unsigned dig); This is my ...
4
votes
3answers
106 views

Recursive methods of singly linked list

Can anyone review the methods? If there are better ways to write a certain method I would appreciate it if anyone could tell me. ...
5
votes
2answers
115 views

BF interpreter in Python that uses recursion to handle loops

I wrote a Brainfuck interpreter in Python and I'm wondering how to simplify it. I handle separately loop commands and the others. A recursive function deals with loops. ...
1
vote
2answers
58 views

Traversing javascript/json based on a dot-separated lookup string

I have an object of arbitrary depth, and a string (or array) containing the keys which have to be traversed to get to the value. As far as I know, there's no method to get to the value directly: ...
2
votes
1answer
43 views

Counting occurrences of “hi” in a string, except where followed by “x”

I already solved this one from CodingBat, but I'm unsatisfied with my solution and I feel I could have made it much shorter. Most of the other recursion tasks could be solved by a one line conditional ...
2
votes
2answers
90 views

Integer to English challenge

I have a challenge, which is to create a JavaScript function that turns a given number into the string representation. For example: console.log(inToEnglish(15)) ...
0
votes
0answers
70 views

Hierarchical Data to Graph

I am using vis.js to visualize some hierarchical data. I have created a recursive routine to add nodes and edges for each group and value in the dataset. I feel like something already exists for this ...
2
votes
1answer
20 views

Liquid navigation tree generator

This include was written for a Jekyll site I'm building. It generates nested HTML unordered lists to a given depth dynamically by parsing page urls. It works fine, but the code feels messy and it ...
5
votes
2answers
191 views

Java 8 Stream to produce all permutations of an array using recursion

I want to write a class that returns a Stream of permutations of an int[]. ...
3
votes
4answers
114 views

Copying file dependencies

I have written the following code, and it works great, but I'm not satisfied. I really love the book "Clean Code" by Uncle Bob and I try to apply all his principles when coding, but I'm having a tough ...
2
votes
1answer
76 views

Object-to-array flattening function

I have written a function that is designed to convert an object into an array of key/pair values ("flattening it") like so: Input ...
2
votes
1answer
71 views

Find all distinct subsets that sum to a given number

The function wants to achieve to find all distinct subsets that sum up to an given number. ...
3
votes
1answer
37 views

Find zeroes in a matrix

I am looking for the elements that are zeroes in a square matrix (of size n), as a list of pair. I don't really like the following code, some condition seems ...
1
vote
0answers
32 views

Recursion into git diff tree using nodegit

I'm using nodegit to develop the backend for a nodejs app that uses a mix of mongodb and git for persistence. The app has to version documents and be able to present diffs between versions, thus the ...
1
vote
0answers
70 views

Finding a Cartesian product of multiple lists

I came up with an extension method to find a Cartesian product of multiple IEnumerable sets. I was able to achieve lazy enumeration via ...
0
votes
0answers
32 views

Show products in dropdown from parent to chid

My goal is a list selector like this: To do this I wrote these methods: First: ...
3
votes
1answer
51 views

SICP - exercise 1.11 - tree recursion

From SICP Exercise 1.11: A function \$f\$ is defined by the rule that: \$f(n) = n\$ if \$n < 3\$, and \$f(n) = f(n-1)+2f(n-2)+3f(n-3)\$ if \$n >= 3\$. Write a procedure ...
5
votes
1answer
104 views

Finding ways to achieve a target sum using recursion

I need your review and suggestions how to make this code better. I'm just learning recursion and sure that this solution is not ideal. Question: Write a function that given an input array of ...
2
votes
2answers
44 views

Computing the largest substring starting with a substring

Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length. ...
3
votes
1answer
40 views

Recursive function to copy over an object with very specific constraints

I totally suck at recursion. I have a function that works but it also looks horribly wrong. I would love to 1) Know how to write it properly 2) Know about resources to read/study so that I don't get ...
2
votes
1answer
39 views

Tail Recursion for Sum - Elixir

I'm new to both Elixir and tail recursion. ...
1
vote
1answer
23 views

Binary Search Tree insert while keeping track of parent for node to be added - iteration 2

Follow up question to Binary Search Tree insert while keeping track of parent for node to be added I am implementing a red black tree for fun and am wondering how I should modify my basic BST ...
0
votes
1answer
26 views

Binary Search Tree insert while keeping track of parent for node to be added

This question has a follow up question: Binary Search Tree insert while keeping track of parent for node to be added - iteration 2 I am implementing a red black tree for fun and am wondering ...
3
votes
1answer
116 views

Tail-recursive call vs looping for a Poker app

I'm developing a Poker app. It is almost done, and I'm looking for improvement. One of the things I wonder is whether I should change how I perform iterations. I currently iterate by using ...
2
votes
1answer
51 views

Basic JSON Representation in Rust

This week I started reading "The Rust Programming Language". As I reached the chapters on enumerations and pattern matching I felt I had enough material to put together a simple representation of JSON ...
5
votes
2answers
56 views

Making the same amount from different combinations of coins (top-down approach)

I was reading a typical interview question found here. Given an amount and a list of denominations, count the number of possible ...
2
votes
0answers
58 views

Generate Subsets Of K Elements From A Set Of Strings

This is the task: Write a recursive program, which prints all subsets of a given set of N words. Example input: words = {'test', 'rock', 'fun'} ...
2
votes
1answer
76 views

Recursive function application

I use a lot T4 templates and want to avoid extra code writing when it could be generated. Currently I have following class: ...
2
votes
1answer
50 views

Reversing all nested sequences

I'm writing a function that returns all (nested) sequences reversed: ...
2
votes
1answer
79 views

Find all the countries I can visit by just crossing direct borders

I was helping on this question. There you have a table border to indicate countryA and countryB have a common border. And want ...
-2
votes
1answer
67 views

Recursive function in JS

EDIT: The code i provide includes a asynchron task in each interation, therefor i need the recursive function, my question is how to beautify the code and apply the proper use. I want to: Remove ...
7
votes
2answers
97 views

Perl recursive copy and move functions

I know a module like this already exists on CPAN, but I wanted to write my own simplified version that accepts wildcards in the input. I don't write many Perl modules so I figured I would post the ...
4
votes
2answers
106 views

Given a path to a directory, print the path to the biggest file in it

Here is my code. I simulated a stack rather than used some regular recursive algorithm because I needed to keep track of two variables: the path to the biggest file and its size. Besides I wrote a few ...
7
votes
1answer
272 views

Path finding algorithm using recursion in Python

Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal. In the maze defined, ...
2
votes
1answer
33 views