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

Boolean evaluation

Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways ...
user avatar
1 vote
0 answers
20 views

Recursive combinations with subsets in Elixir

...
user avatar
  • 111
2 votes
1 answer
37 views

Locate Primitive Value in Nested Sequence Type - Iterative version is slower than equivalent recursive function

I'm looking for advice on how to improve the performance and/or style of these two search functions. This is just for fun and for practice: they are already fast enough for any application I would ...
user avatar
0 votes
1 answer
73 views

Can I optimize my implementation of generating Fibonacci series using recursion?

My function accepts a number, which generates total Fibonacci numbers. I am using recursion. Please follow the code below, ...
user avatar
2 votes
1 answer
48 views

Coin partitions

I am looking to obtain the partitions of coins that sum to a target amount So I tried search online, but every single website loves to use this problem to show the benefits of dynamic programming. ...
user avatar
0 votes
1 answer
40 views

Asynchronous recursive function for generating a unique Id

The code below is my first purpose built asynchronous recursive function. It took me a while to figure out how to write the thing, and I would like a second opinion. It's part of a project for The ...
user avatar
0 votes
0 answers
72 views

Constructing a dependency list recursively

I am trying to find if there is better way to do this recursion. I went through some examples of memoization but found myself struggling to implement that with my code. example data: db_data and ...
user avatar
  • 1
2 votes
2 answers
105 views

Optimizing a recursive path finding algorithm

On input i get width and height of matrix, string of text and another string of finalText I want to reach. The characters of the first string are assigned to matrix. My goal is to find shortest way to ...
user avatar
  • 21
0 votes
0 answers
21 views

Range Sum of BST Leetcode - Python pass by reference?

https://leetcode.com/problems/range-sum-of-bst/ I'm trying to solve this question using Python and the solution is quite straightforward, start from the root and brach left, right based on the value ...
user avatar
0 votes
1 answer
35 views

Function for inserting values in a nxn matrix by changing directions inside of it

I am relatively new to C++ and I had this task to solve, where you are given a number and you have to create an nxn array of integers, where you would have to continually switch directions (right, ...
user avatar
  • 1
0 votes
2 answers
113 views

Sequential Search - Recursion

I have written this program to search for a value in an array using sequential search. And well, I've been trying to implement the same algorithm using recursive structure. is this a good ...
user avatar
0 votes
2 answers
207 views

Finding the largest value in array - Recursion

I know this may be a silly question (I'm just learning about recursion, and I think there are still things that are still not clear to me.), but... is this a good implementation of a recursive ...
user avatar
4 votes
2 answers
93 views

Binary Search Tree - My own version of delete function

Well, I am recently learning data structures and algorithms and I came across the Binary search tree and decided to first time use my own logic to make the delete function. I have not come across a ...
user avatar
0 votes
1 answer
54 views

Given a matrix return true if it contains the Identity matrix (by recursion)

I need to write recursive static method with given 3 parameters the method will return true if the sub matrix with the size of (int size) which the left corner is mat[x][x] is the identity matrix ...
user avatar
1 vote
0 answers
103 views

How to make recursive a nested map function that takes info from different arrays JS

I am making an inventory application and I must create a function that allows me to perform different operations with the arrays that I have created, the application consumes data from an api and ...
user avatar
1 vote
2 answers
126 views

size() method for a binary search tree

This is my size method for my binary search tree, that is meant to implement recursion to calculate the tree's size. ...
user avatar
7 votes
3 answers
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 ...
user avatar
  • 393
2 votes
1 answer
65 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 ...
user avatar
4 votes
1 answer
48 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 ...
user avatar
1 vote
2 answers
64 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? ...
user avatar
-3 votes
1 answer
201 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 <...
user avatar
4 votes
0 answers
203 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 (...
user avatar
3 votes
2 answers
156 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 ...
user avatar
  • 3,556
1 vote
0 answers
43 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 ...
user avatar
3 votes
0 answers
74 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 ...
user avatar
  • 3,556
2 votes
2 answers
101 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. ...
user avatar
  • 602
2 votes
1 answer
77 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. ...
user avatar
0 votes
1 answer
68 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 ...
user avatar
1 vote
2 answers
41 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 ...
user avatar
  • 3,556
2 votes
1 answer
56 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 ...
user avatar
  • 3,556
1 vote
1 answer
207 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 ...
user avatar
2 votes
1 answer
39 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 ...
user avatar
1 vote
0 answers
101 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 ...
user avatar
0 votes
1 answer
68 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: ...
user avatar
3 votes
2 answers
388 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: ...
user avatar
2 votes
1 answer
59 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 ...
user avatar
5 votes
1 answer
142 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. ...
user avatar
4 votes
1 answer
356 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']): ...
user avatar
1 vote
1 answer
64 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 ...
user avatar
1 vote
0 answers
83 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 ...
user avatar
10 votes
2 answers
2k views

My recursive attempt at Collatz Sequence in Python

...
user avatar
6 votes
2 answers
218 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 ...
user avatar
4 votes
1 answer
206 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' ...
user avatar
  • 41
1 vote
1 answer
852 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 ...
user avatar
2 votes
1 answer
82 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 ...
user avatar
  • 3,556
2 votes
1 answer
121 views

Longest common subsequence — recursion and memoization

...
user avatar
  • 155
1 vote
0 answers
65 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 ...
user avatar
  • 3,556
3 votes
2 answers
71 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. ...
user avatar
0 votes
1 answer
95 views

How do I optimize my GetChildren method

UPDATED I have a POCO class that is populated with _context.Categories.Load(): ...
user avatar
  • 487
1 vote
3 answers
77 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 ...
user avatar

1
2 3 4 5
22