Questions tagged [recursion]

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.

Filter by
Sorted by
Tagged with
2
votes
0answers
19 views

File and folder filter for a “last-updated explorer”

Sometimes I save a file somewhere but can't find it after or I install something and want to see what files were added. For this reason, I created a winforms app which only displayes files created/...
3
votes
1answer
32 views

User defined function call on a stack based interpreter for concatenative language

I would like to receive some advice on how to improve a small concatenative stack-based interpreter, executing a joy-like programming language. It is really minimal, and is in fact a subset of a ...
1
vote
1answer
44 views

Tower of Hanoi, ASCII animation with ANSI escape codes

A few days ago I saw a nice video on YouTube with prof Thorsten Altenkirch about recursion and the Tower of Hanoi puzzle. Today I tried to reproduce the code from the video and came to this: ...
4
votes
2answers
103 views

Get list of all combinations from a set

Given a tuple of elements, in elementTupleParam and the number in each combination r, we compute all the possible combinations ...
7
votes
2answers
109 views

Letter Combinations of a phone number using a Dictionary

Problem statement (online source) Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone ...
5
votes
2answers
321 views

Selection Sort Algorithm (Node.js)

I wanted to implement a selection sort and wanted to make sure that I'm doing it correctly. I wanted to do it in a way that's efficient and use recursion. Please let me know if I am doing this ...
10
votes
1answer
103 views

Recursive code to generate a parametric sweep of input values

I generate a set of data based off every combination of inputs. The source range that's inputs requires headers to identify the parameters. In its present state I'm not content as it's not as ...
4
votes
2answers
111 views

Build a flat List from a Tree structure in Java

I have a Tree structure represented by a List, which I want to get it flattened. I wrote the function below: ...
3
votes
1answer
35 views

Batch rename files recursively, and number the directory index

When dealing with iOS app bundle, It is not convenient to get the file by its path, but loading it by its name. Need to batch rename images recursively, with Mac Bash. And to make the name unique, ...
1
vote
0answers
62 views

Recursion to dynamic programming [closed]

I was trying to solve a problem on de-arrangements (Number of partial derangement such that exactly prime number discs are found away from their natural positions? (Any number of non-prime K disks ...
5
votes
0answers
70 views

Mahjong hand completeness checking algorithm

As a summer project, I have been working on a small-scale, console-based version of Mahjong (the Rummy-like hand completion game, and not the solitaire version). While having prior knowledge of the ...
4
votes
1answer
91 views

Change tracking POCO entities

Description In a time where thin clients, web browsers, web services and micro services are prevalent, we tend to forget we still have to deal with thick and smart clients. Many applications in B2B ...
5
votes
0answers
37 views

JS deep merging of objects- removing empty keys

I've written a helper for combining objects (deep merge). It works, and is flexible to add options (like uniq and replace). ...
2
votes
0answers
33 views

Leetcode Finding Maximum Area of Island Solution

Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are ...
2
votes
1answer
38 views

Convert Sorted Array to Height Balanced Binary Search Tree

Algorithm This is my code to convert a sorted vector of integers to a balanced binary tree of the same content. The binary tree is made of these nodes: ...
19
votes
3answers
4k views

Loading military units into ships optimally, using backtracking

I solved the following problem using backtracking: We are given a list of military units, their weight and their (numerical) strength. We have a number of ships with a limited carrying capacity....
3
votes
2answers
59 views

Fixed Content Necklace Generator

I wrote a class that generates combinatorial necklaces with fixed content as per Sawada: A fast algorithm to generate necklaces with fixed content. The class is instantiated with an input list that ...
5
votes
2answers
152 views

Code Challenge: basic arithmic operations using only incrementation operator

Challenge Write a function that takes 2 integer operands left and right (both >= 0) and evaluates one of the following ...
7
votes
3answers
248 views

Sierpinski turtle triangle

I am working through Programming Fundamentals with Python on Udacity. The assignment was to create a recursive triangle. I am happy with the output, but I am hoping for feedback on the actual ...
4
votes
1answer
47 views

Find the total number of emails in a folder (with all of the subfolders)

The Folder struct definition below is given: type Folder struct { ID int emailCount int childFolderIDs []int } Description of the fields are: ...
2
votes
1answer
48 views

Traversing two trees until a common value has been found

I am traversing two objects that may share a common ancestor. To make the code small enough to show here, I have changed it into two dictionaries with values. As you can see, ...
9
votes
2answers
755 views

Recursive search on Node Tree with Linq and Queue

This code is now maintained on GitHub I've created a Node class which contains two important properties: ...
3
votes
1answer
109 views

Find A Series of Numbers Who when Squared and Summed are equal to a given Square

I am working on a CodeWars titled 'Square into Squares. Protect trees!' it can be found here: https://www.codewars.com/kata/54eb33e5bc1a25440d000891/train/javascript I have a working solution, the ...
5
votes
0answers
164 views

Recursive conversion from ExpandoObject to Dictionary<string, object> #2

Because my original question was lacking many details, I have been advised to ask a new question. I will repeat the important parts of the original question and add examples etc to hopefully make it ...
4
votes
4answers
699 views

Recursive conversion from ExpandoObject to Dictionary<string, object>

For my blazor library which is a modification of this awesome library I have to convert an ExpandoObject into a ...
1
vote
2answers
83 views

Combined looping and recursion when implementing Quicksort, using proper Clojure style

In "The Joy of Clojure", 2nd edition, code for quicksort is introduced on page 133 that I found hard to digest. I have rewritten it to make it clearer (at least to myself). Here is the original: <...
7
votes
3answers
533 views

Compiling all Exception messages into a string

Below is a recursive function I've written that's responsible for compiling a string consisting of a Exception's message, and also each of that ...
0
votes
1answer
25 views

Uncompressing a list with some run-length-encoded elements

Regarding the following code ...
5
votes
2answers
411 views

Fetch and print all properties of an object graph as string

Below I have setup an extension method that takes any object, cycles through its properties, and prints each out to a Console window in the format Name: Value. ...
5
votes
1answer
198 views

A recursive Boggle solver

`Boggle is a word game in which letters are randomly placed in a 4x4 grid e.g: A D Q P N L E M O S R T V K J H Words can be started from any letter and are ...
8
votes
4answers
3k views

“What is the maximum that Player 1 can win?”

This is a question that I encountered in one of the competitive coding tests. The question goes as follows: A 2-player game is being played. There is a single pile of stones. Every stone has an ...
9
votes
1answer
116 views

Tower of Hanoi with helper function

Here is my solution to the Tower of Hanoi problem using Python ...
4
votes
3answers
400 views

Generate parentheses solution

I have coded a solution to build all valid permutations of parentheses. My code is below. I have a question on my code based on a comment by my PEP8 checker. It said that there was no need to ...
2
votes
0answers
46 views

JSON flattening with object duplication on array property for CSV generation

I am looking for a way to transform JSON data into a flat "csv-like" data object. In some way, I am looking to "sqlirize" a mongodb collection. I have already check some json flat libraries in NPM ...
2
votes
2answers
93 views

Generating recursive class instances from an array of splitted values by dashes (as a folder tree)

Well, I'm trying to generate the following: Input: ...
3
votes
1answer
712 views

Get all children recursively in Entity Framework Core

In Entity Framework Core we can have recursive entities. But we cannot do an "Include" for these recursives (can we?). So I wrote a Get-method that does it for me: ...
2
votes
1answer
33 views

Performing an action which may return other actions to be performed, concurrently

I have a program which, at its core, involves repeatedly performing an action on some value, and based on that action also returning a list of new values to perform that action on. The pure version of ...
3
votes
0answers
42 views

reverse recursive search on an object with javascript - like tree search

I implemented a tree search with JavaScript. It has below basic rules. It will search over an array of objects which has recursive(like fractal) If it found a according data in a leaf(the final ...
1
vote
1answer
70 views

Python program to find the factorial of a number using recursion

A factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 5 (denoted as <...
3
votes
1answer
174 views

Matryoshka Doll Recursion

I was tasked with writing a Matryoshka doll program that manages the following: howManyDolls : returns an integer based on how many dolls are inside the stack howManyWearingBabushkas : returns an ...
3
votes
1answer
51 views

Efficiency of a recursive implementation of the Sieve of Erasthotenes in Python

I implemented the Sieve of Erasthotenes recursively using filter and I was wondering how efficient this implementation is and wether a non-recursive implementation ...
3
votes
1answer
68 views

Adding an item to a hierarchical data structure

What I need to do is create a new object, modify it using a recursive function, then merge it with another object, and do this all in such a way that the values of the new object take precedence over ...
2
votes
1answer
44 views

Convert Tail-Call Recursive Code to Loop [closed]

So, I'm in the midst of writing a programming language interpreter in Python, and one of the problems I'm concerned about is that since I've been using a lot of recursions to implement the interpreter,...
4
votes
1answer
158 views

Return all valid paren strings with a given length

The problem is Given a non-negative integer n, return all valid parentheses strings with n open parens and ...
6
votes
1answer
85 views

Rendering tree of nodes as string

I'm creating a debug-view for my expression-trees. They record each operation automatically in a tree that I am transforming into string so that I can see the exact ...
1
vote
1answer
39 views

Depth-first traversal implementation in Java (by recursion)

I implemented a recursive depth-first traversal, with all three traversal modes in this function. Is this the most succinct way to write the code? ...
0
votes
1answer
40 views

Delete directory tree function

I made this function to delete a directory with all its contents recursively, will it work as expected in a production environment ? is it safe ? I don't want to wake up one day with ...
4
votes
1answer
35 views

Processing file inclusion directives using mutual recursion

I am preprocessing a set of files where one file is included in another file with an include tag like shown below: file A ...
4
votes
2answers
132 views

Roman Numbers - The Functional Way

Yet another exercise in converting values between the decimal and roman number systems. I have tried the functional way. Any comments are welcome - but I'm especially interested in answers focusing ...
5
votes
1answer
156 views

A cartesian product of tuples in C++17

I would like to write a function that computes a cartesian product of two tuples in C++17 (the tuples can be of type std::tuple or ...