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
1answer
9 views

Delete node in a list with passing by reference in C [on hold]

Given the following code for deletion of an element in a doubly linked list not circular: ...
0
votes
1answer
44 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
19 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
55 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 ...
-4
votes
0answers
10 views

Recursive Base Conversion (Base 2, Base 5, Base 7, Base 8) Java [closed]

I recently created a base conversion program for my java class and my teacher says I have errors with the program. Could anyone test this program and tell me what the errors are and how to resolve ...
1
vote
0answers
29 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
37 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\$. ...
-3
votes
0answers
33 views

Code for Sylvester sequence [closed]

I need to code the Sylvester sequence in Python. The formula for the sequence is defined as $$s_n = 1 + \prod_{i=0}^{n-1}s_i$$ Where \$s_0 = 2\$. However, I am having too much trouble writing this ...
0
votes
1answer
26 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
23 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
19 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
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
96 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
103 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
53 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
42 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
84 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
62 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
19 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
154 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
71 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
64 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
35 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
29 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
59 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
97 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
43 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
28 views

Tail Recursion for Sum - Elixir

I'm new to both Elixir and tail recursion. ...
1
vote
1answer
21 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
46 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
52 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
74 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
49 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
66 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
87 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
205 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
94 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
749 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 ...