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

1
vote
0answers
11 views

Get all combination of a nested object with arbitrary levels in javascript

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. And I would like to return all ...
2
votes
2answers
39 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
83 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. ...
-1
votes
0answers
11 views

Recursive insert method for a singly linked list [on hold]

I've been trying to write recursively various methods on a singly linked list. Here's the insert method where I have to insert an element at a specific index (not at the end). Here's what I've ...
5
votes
2answers
96 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
50 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
41 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
79 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
48 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
18 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
132 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
98 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
70 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
63 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
33 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
25 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
55 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
28 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
49 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
93 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
42 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
0answers
22 views

Tail Recursion for Sum - Elixir

I'm new to both Elixir and tail recursion. ...
1
vote
1answer
20 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
24 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
45 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
48 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
54 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
73 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
46 views

Reversing all nested sequences

I'm writing a function that returns all (nested) sequences reversed: ...
2
votes
1answer
77 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
65 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 ...
6
votes
2answers
62 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
105 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
176 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
1
vote
4answers
109 views

Negative factorial in JavaScript

I was doing a basic problem on coding a factorial \$n!\$: ...
7
votes
1answer
87 views

Recursive program for generating and printing all permutations of the numbers 1, 2, …, n for given integer number n

I've just written code for generating all permutations of the numbers from 1 to n in Java. It seems to work, but I think it's a bit more complex than it needs to be. ...
6
votes
1answer
66 views

Pick sequences of numbers to maximize the points

It is a single-player game. In the beginning, there is a row of integers. In one move the player can take a certain amount of adjacent numbers (let's denote it T). Then the player's points increase ...
7
votes
3answers
695 views

Check if 2 arrays have (exactly) the same elements recursively

I've been given a homework assignment to make a function to check whether 2 given arrays with the same given size have exactly the same set of elements. My function seems to be working but I feel ...
-7
votes
1answer
65 views

Counting number of steps while finding right path [closed]

I am writing a code which would return the path in a maze using recursion, but now with the path I also want the number of steps. How do count number of steps in this program? or number of times ...
2
votes
0answers
41 views

Recursive implementation of integer partition without re-arrangement

Problem: Integer partition without re-arrangement Input: An arrangement S of nonnegative numbers {s1, . . . , sn} and an ...
4
votes
4answers
122 views

Finding the max sequence finder

Problem Statement Find the max sequence finder. findMaxSequence([3, 2, 3, 4, 2, 2, 4]); ...
3
votes
0answers
41 views

Recurse on complex Perl data structure, applying needed rules

Inspired by this answer and previous a commentator of code review use: Given a complex Perl data structure, traverse/jigger/modify as follows: If ORACLE_SID is ...
17
votes
4answers
4k views

Print the Twelve Days of Christmas without loops or conditionals

For my AP Computer Science class, I am required to write a program that prints the Twelve Days of Christmas without loops or conditionals using static methods. ...
4
votes
3answers
112 views

A “map” function that alternates between two mapping functions

I am trying to solve following problem in Haskell using recursion: Define a recursive function funkyMap :: (a -> b) -> (a -> b) -> [a] -> [b] ...
2
votes
2answers
118 views

Code optimization of recursive function

I have a mathematical function as shown below $$ (h+1) * U(k,h) = \sum_{r=0}^k \sum_{s=0}^h (r + 1) * (k - r + 1) * U(r + 1, h - s) * U(k - r + 1, s)\ + \sum_{r=0}^k \sum_{s=0}^h (k - r + 1) * ...
6
votes
2answers
106 views

A recursive program that attempts to solve an extremely large number

This is my recursive program for the following function: \$F(x) = G(x) - W(x)\$ \$G(x) = [G(x-1)+G(x-2)]^2\$ \$W(x) = [W(x-1)]^2 + [W(x-2)]^2\$ If x == 0 in either function G or function W, then ...
6
votes
1answer
91 views

Function that recursively downloads entire directory is slow

I created this function to recursively copy an entire directory from an FTP server. It works just fine except that it is about 4 times slower than using FileZilla to do the same operation. It takes ...