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
0
votes
0answers
6 views

The variables inside of a recursion [closed]

So, I've done this problem on CodeWars: Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The ...
1
vote
1answer
40 views

Recursively access deeply nested object

Problem Statement I need to access a deeply nested object. I could've used a 3rd party util such as Lodash but insisted myself on writing a Vanilla JS solution with a recursive strategy. Code Can this ...
2
votes
1answer
52 views

A recursive_transform template function for the multiple parameters cases in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++. Thanks for G. Sliepen's answer. Based on the mentioned suggestion, I am attempting to ...
2
votes
1answer
65 views

Longest common subsequence — recursion and memoization

...
1
vote
0answers
56 views

A recursive_transform template function for the binary operation cases with execution policy in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++, A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary ...
3
votes
2answers
63 views

How to refactor an imperative function recursively?

I have an HL7 MLLP message building class I'd like to refactor. The way HL7 over MLLP works is there are multiple fields, usually delimited by the | character. ...
0
votes
1answer
91 views

How do I optimize my GetChildren method

UPDATED I have a POCO class that is populated with _context.Categories.Load(): ...
1
vote
3answers
62 views

Recursive power (mathematical operation) function in C

How to make a C recursive exponentiation (power) function better? I developed a pretty simple (yet decent, imo) power function for the sake of learning. I'm not quite trying to compete with ...
2
votes
1answer
82 views

A recursive_transform template function for the binary operation cases in C++

This is a follow-up question for A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_print Function For Various ...
7
votes
2answers
460 views

C delete files and directories, recursively if directory

This is my function that uses recursion to recursively delete a directory. I like my way of skipping entries . and ... But ...
3
votes
1answer
117 views

Killing a Hydra - Overengineered

Background This question is inspired by the question: Killing a hydra, and my response therein. I will restate the problem at hand in full so that this question is fully self contained You can only ...
3
votes
2answers
81 views

Haskell Function to get the List representation of an Integral

This is a simple practice problem. The task is to write a function getLR that receives an Integral, ...
0
votes
1answer
128 views

Return Lists from Recursive Function C#

I would like to return or save for later use in the ParallelSums function what I currently have printing out to the console in the findAllSubsetsRec function. If I pass the ParallelSums function an ...
1
vote
1answer
41 views

Equivalent partition sums

I'm looking for feedback on my solution to the following prompt: Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements ...
4
votes
2answers
97 views

Simple Python Recursive Web Scraper

I tried to make a simple recursive web scraper using Python. My idea was to grab all the links, titles and tag names. Website: https://lifebridgecapital.com/podcast/ Course of Action: Grab all the ...
0
votes
0answers
57 views

How to split recursively a dataset according to one of its attributes?

I want to split a dataset recursively according to one of its attributes (attVal) and based on others datasets attributes values like the following : Given the ...
8
votes
1answer
168 views

Find all paths in a graph

My code does a DFS on the given graph and prints all possible paths for a given start and end node. My question is how can this be improved? Can some form of memoization be used here? There are cases ...
0
votes
1answer
64 views

Perform sum of squared numbers without using for loop

I have to find the sum of number after performing square operation in the given input the negative numbers need to be ignored. The input Format is, first line is number of test cases followed by N as ...
-1
votes
1answer
79 views

Recursive Palindrome in JavaScript

Would someone review this code, and confirm that it is indeed recursive? I'm learning computer science and going through different types of algorithms. Right now, I'm focusing on recursion want to ...
5
votes
3answers
962 views

Separating the even and odd numbers in an array in C

I wrote a working program in C that takes an array with size 2ⁿ, and separates all the even numbers from the odd numbers. For example: Input: {1,2,3,4,5,6,7,8}, Output: {8,2,6,4,5,3,7,1} I want my ...
0
votes
1answer
38 views

extents_to_array and array_to_extents functions for Boost.MultiArray in C++

This is a follow-up question for A get_extents helper function for Boost.MultiArray in C++. In order to retrieve, manipulate and calculate size information in each dimension from Boost.MultiArray in ...
3
votes
0answers
55 views

Lisp expression parser

I'm building a very simple Lisp interpreter. Similar to the the one from here. Here is what I have so far for the parsing part, that is, everything from "text is passed to the the program" ...
0
votes
0answers
34 views

Enumerating all fixed-length paths from a vertex in a graph

Enumerating all fixed-length paths from a vertex in a graph 1. Graph-related classes Base implementations of the relevant classes in my graph library. I'm using C#9 in a .NET 5 project. I opted to use ...
3
votes
0answers
62 views

A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template Function Implementation with ...
0
votes
0answers
33 views

A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
0
votes
0answers
47 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion(updated)

Follow up to Efficiently calculate value of Pascal's Triangle using memoization and recursion Based on feedback given by jvwh in the answers ...
2
votes
1answer
61 views

Recursive type checking for containers

This code checks the type, length and depth (highest number of nested containers) of the container as well as the type of its sub-containers and its elements. There are also two simple methods for ...
3
votes
1answer
63 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion

So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
0
votes
2answers
66 views

A recursive function to reverse string

Write a recursive version of the function reverse(s), which reverses the string s in place. I'm studying K&R and wrote a code for the question. ...
1
vote
1answer
66 views

String tokenizer

Objective: Create a function called wordsAndSpaces that splits a string on groups of spaces, preserving each group of space characters as a single token. Example: <...
1
vote
1answer
48 views

Maintaining state while walking a tree structure

The following code creates a simple tree structure and then walks through the tree looking for node with the value 9 that appears after we have seen a node with the value 1 and a node with the value 4 ...
3
votes
1answer
100 views

Pokemon Soul Link tracker

I've just finished writing a program to help track Pokemon across Soul Links. The goal of the program is to take in the names of the two Pokemon alongside the route that they were caught on. The ...
2
votes
1answer
123 views

C++17 Recursive Fibonacci calculation with memoization

Compiler is g++ 4.2. I'm new to C++, but I've done a lot of data science, web scraping, and some socketing stuff in Python. This code generates the nth Fibonacci number, either with a naive ...
3
votes
2answers
169 views

Downloading and parsing research papers

I am trying to write a script which gets a research paper from a website by calling their API and then traverse it sentence-wise with some conditions. The paper is accessible in XML format. I am ...
1
vote
1answer
61 views

“Sequence full of colors” challenge on HackerRank

This is the challenge: You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the ...
2
votes
1answer
70 views

Guess Number Game - Console based game using Java

This game is pretty common for beginner projects. I wrote a version of this before all in Main - so here I challenge myself to recreate it in a more OO style. I wanted to take a more OO approach, so ...
1
vote
3answers
98 views

Advent of Code 2020, Day 10 in Ruby

I'm an amateur programmer making a career change into web development. I've found Advent of Code challenges are great way to sharpen my skills. I've cleaned up this solution for Day 10, 2020 as much ...
2
votes
3answers
114 views

DFS-based exhaustive word grid search

I have implemented an exhaustive depth-first grid search that searches for all possible words in the 8 connected regions. Is there any way I can make this faster or memory efficient than it is now? I ...
11
votes
2answers
411 views

Finding acronyms with >=1 letters at the start of each consecutive word

Problem I'm seeking a clean and efficient way to determine whether one string is an initialism/acronym of another. Example: IBM => International Business Machines However, a key condition for my ...
0
votes
0answers
45 views

A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count_if Function with Unwrap Level for Various Type Arbitrary ...
0
votes
1answer
36 views

Find a powerset of a set in C

The code below is an implementation of purely recursive solution to find a powerset of any given set. The input set is a string, and the output - array of strings. Both of them are wrapped into a ...
4
votes
2answers
65 views

Primality Test Refactoring

I devised a new primality test isPrimeNumber() below which determines if 1000000007 is prime. It works fine but the code looks unprofessional in my opinion. Is there any way to refactor it to make it ...
1
vote
0answers
58 views

A Function Applier for Applying Various Algorithms on Nested Container Things in C++

This is a follow-up question for A recursive_replace_if Template Function Implementation in C++, A recursive_copy_if Template Function Implementation in C++, A recursive_count_if Function with Unwrap ...
1
vote
0answers
45 views

A recursive_replace_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_copy_if Template Function Implementation in C++. Besides the recursive version std::ranges::copy_if, I am trying to ...
2
votes
1answer
49 views

A recursive_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_transform for std::vector with various return type and A recursive_transform Template Function Implementation with std::invocable concept in C++. Besides ...
1
vote
1answer
67 views

A recursive_transform Template Function Implementation with recursive_invoke_result_t and std::ranges::transform in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function Implementation with std::invocable ...
3
votes
2answers
120 views

Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function ...
2
votes
1answer
72 views

A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template ...
2
votes
1answer
109 views

A recursive_transform Template Function Implementation with std::invocable concept in C++

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Template Function with Execution Policy, A recursive_count_if Template Function ...
2
votes
1answer
66 views

A recursive_count_if Template Function with Execution Policy in C++

This is a follow-up question for Avoiding requires clause if possible on a series recursive function in C++ and A recursive_count_if Function with Automatic Type Deducing from Lambda for Various Type ...

1
2 3 4 5
21