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
1
vote
0answers
20 views

Implementing a correct `let rec in` interpreter in Haskell with `eval` and `sub` semantics

I'm implementing the toy fb-lang from the principles of programming language book. It's a small interpreted language that uses eval(uate) expression function and <...
7
votes
3answers
1k views

Finding the majority element in an array

A list is said to have a “majority element” if more than half of its entries are identical. In this classical problem the goal consists of determining whether a list a of length n has a majority ...
2
votes
1answer
61 views

Given an array return true if can be splitted to two groups with same number of cells and same sum

Given an array, the method should return true if you can split it to two groups with the same number of cells and so the sum will be equal. It needs to be done by recursion, and can't change the array ...
3
votes
0answers
25 views

Recursively Copy Dotfiles from Git Repo to New System's Home Directory

I manage my dotfiles in a github repo. The idea would be that I could clone the repo if I ever have to develop on a new system and symlink them to the home ...
1
vote
2answers
58 views

Binary Search using recursive approach

Is the following implementation of recursive function correct? How about the time complexity of the code; is it good in terms of performance? ...
-3
votes
1answer
64 views

method to check if number is ascending order by recursion

method name: public static boolean ascendingNum(int n) method need to be done by recursion and return if the given number is in ascending order from right to left <...
2
votes
0answers
50 views

Tree for PowerShell

This Module started as a fun coding exercise designed to emulate the tree command and also calculate the size of each folder based of the files size of that folder (...
3
votes
2answers
140 views

Manhattan distance calculation between two images in C++

This is a follow-up question for Two dimensional gaussian image generator in C++ and Image pixelwise operation function with multiple inputs in C++. For learning C++20 and researching purposes, I am ...
1
vote
0answers
36 views

How can I optimise my recursive backtracking sudoku algorithm?

I've tried optimising my program by removing invalid values for possible spaces instead of searching from 1-9, and by choosing values with the lowest number of empty spaces in its row and column, but ...
3
votes
0answers
43 views

Order guaranteed recursive_transform template function implementation with execution policy in C++

This is a follow-up question for A recursive_transform Template Function with Execution Policy, A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy ...
2
votes
2answers
61 views

Arithmetic progression using Recursion

take an array of two numbers who are not necessarily in order, and then add not just those numbers but any numbers in between. For example, [3,1] will be the same as 1+2+3 and not just 3+1. ...
2
votes
1answer
53 views

Finding possible combinations for n<7 with rust

I am trying to learn rust and as such have been redoing some of the challenges on project Rosalind. This one relates to the challenge Enumerating Gene Orders. ...
0
votes
1answer
67 views

PHP game - changing color of cells in a blue and white grid => updating groups of white cells that touch each other

My game is a grid in which you have to change cells color by clicking on them. When I generate a grid I have to know all the possible combinations of blue and white cells my game allows, to know the ...
1
vote
2answers
38 views

A recursive_count function with recursive_depth for unwrap_level checking in C++

This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++ and A recursive_count Function with Unwrap Level for Various Type Arbitrary ...
2
votes
1answer
52 views

A recursive_depth function for calculating depth of nested types implementation in C++

This is a follow-up question for A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++. A function ...
1
vote
1answer
75 views

Helper get_all_neighbors (in a grid) function - python

So a little context to understand the code: This is a helper function to solve a bigger problem here Quick summary: A Knight is in a dungeon/2D grid of Ints, starts at 0,0 and must reach the last ...
2
votes
1answer
34 views

Recursion to generate fractal

I used recursion to generate fractal and got the desired result but I think my code can be better I started using MATLAB a few days ago and since than trying and learning new things. Now this code ...
1
vote
0answers
39 views

Small recursive script in go to clone all projects in a Group

I've just created a small script to clone all projects within a Gitlab Group and all Subgroups inside it. As I am trying to level up my Go skills, I would welcome any reviews and enhancement on my ...
0
votes
1answer
62 views

Recursive function that gives the number of hashes present in a Merkle Mountain Range proof

I have written a function that gives the number of hashes present in a Merkle Mountain Range proof. Using Solidity, this function can be written as: ...
3
votes
2answers
365 views

Asynchronous and recursive word square generator in C#

Overview I've created an asynchronous and recursive method of generating word squares, of any size (known as the order of the square), from a known word list. If you're unfamiliar with word squares: ...
2
votes
1answer
44 views

Find ALL duplicate subtrees. using recursion

This is just a practice exercise, I'm trying to understand dynamic programming as deeply as I can. I solved this using recursion, though I am not sure if it will always work. If anyone could tell me a ...
5
votes
1answer
98 views

Simple expression evaluator in Rust

What follows is an evaluator for a toy expression language. The language includes functions of a single variable (with lexical binding), along with numbers and a way to apply functions to expressions. ...
3
votes
1answer
207 views

Generate possible combinations by range and length

I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. ['a'..'z']): ...
1
vote
1answer
44 views

Recursively unpacking a javascript object

I'm seeing a React course, we were studying fundamentals of javascript for a while. We saw how to access the content of an object and display it in console. My solution for the problem of displaying ...
1
vote
0answers
47 views

Codewars: Path Finder

Task You are at position [0, 0] in maze NxN and you can only move in one of the four cardinal directions (i.e. North, East, South, West). Return true if you can reach position [N-1, N-1] or false ...
10
votes
2answers
2k views
6
votes
2answers
169 views

Python backtracking algorithm to solve sudoku

I have recently gotten back into writing python and i decided to take up a project of writing a backtracking algorithm in python to solve Sudoku puzzles How it Works A matrix is declared to represent ...
4
votes
1answer
172 views

recursive bin packing

For the company I work for we spec lengths of tube of varying lengths. For a given project let's say there is a list like this 100', 115', 105', 205', 195', 240', 240', 130', 180', 140', 225', 85' ...
1
vote
1answer
65 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
77 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
99 views

Longest common subsequence — recursion and memoization

...
1
vote
0answers
63 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
67 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
92 views

How do I optimize my GetChildren method

UPDATED I have a POCO class that is populated with _context.Categories.Load(): ...
1
vote
3answers
67 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
92 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
828 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
143 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
103 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
719 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
43 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 ...
3
votes
2answers
134 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 ...
8
votes
1answer
287 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
75 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
126 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
973 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
41 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
65 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
36 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
88 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 ...

1
2 3 4 5
22