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
4 votes
1 answer
104 views

Ackermann-Péter function call count using Writer monad

I'm quite new to Monads and I tried add function call counting to the Ackermann function code. The goal was simplicity, not performance. I want to have code review on the ...
0 votes
1 answer
64 views

The usages of make_view Template Function in C++

This is a follow-up question for A recursive_transform_view Template Function which returns a view in C++. I am trying to revise the structure of recursive_transform...
  • 3,768
2 votes
2 answers
82 views

A recursive_transform_view Template Function which returns a view in C++

This is a follow-up question for A recursive_transform_view Template Function Implementation. Following the suggestions mentioned in G. Sliepen's answer: Of course, it might be interesting in itself ...
  • 3,768
3 votes
2 answers
113 views

A recursive_transform_view Template Function Implementation

This is a follow-up question for A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++. Considering the suggestion mentioned in Davislor's answer, I am trying ...
  • 3,768
3 votes
2 answers
111 views

A recursive_transform Template Function with Unwrap Level for std::array Implementation 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++. I am following the suggestions proposed by ...
  • 3,768
2 votes
2 answers
102 views

Generate the number of partitions of each integer

I've coded a program that calculates the number of partitions of n into at least two distinct parts, and is relatively quick too (about N^1.5 complexity). For input 30 000 it takes roughly 4 seconds. ...
  • 21
2 votes
1 answer
55 views

Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity

The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
0 votes
1 answer
78 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
1 vote
0 answers
41 views

Traversing a 2D array with a tree

In order to help me solve the December Jane Street puzzle "Die Agony" I wrote a quick and dirty script to manually brute-force through the thing and do the calculations for me. I then tried ...
5 votes
5 answers
520 views

Find the 10 largest files in a directory tree

I've recently finished a small project intended to better understand C. The program will output the ten largest files found (recursively in the event of subdirectories) in a specified directory. I've ...
0 votes
1 answer
54 views

Checking several strings against a n-depth list of lists and returning one if its values

The data structure I am working with is a list of lists that is created by parsing a file. The depth of the list can vary. The list can have n Strings before its child-value begins. My current example ...
  • 161
3 votes
2 answers
191 views

"Sudo Mode" in VBA to Let UDFs Modify Workbook

Background I am working on a VBA paradigm for modifying the Excel environment from a UDF. I call this "sudo mode", and I leverage Application.Run() to ...
  • 349
1 vote
0 answers
61 views

Traveling salesman (Dynamic Approach) retrieve path without losing on time complexity

It is difficult to find resources on above programming problem therefore I've decided to ask a question on this forum. Using memoization and dynamic programming we can obtain a code that gives \$O(2^N ...
  • 11
5 votes
2 answers
617 views

Recursively calculating powers by squaring

Consider the following function that implements optimised O(log n) exponentiation by squaring: ...
3 votes
0 answers
83 views

Finding the number of possible paths in a cave system (Python)

I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
7 votes
1 answer
352 views

Get all partitions of an array into k non-empty sub-arrays

I am writing a function that takes an array and an integer number and returns an array of all the partitions into subarrays (so an array of arrays of subarrays). The number of subarrays is exact the ...
  • 305
1 vote
0 answers
108 views

Find shortest knight's path between two chessboard squares

My function is a solution to the Knight's Travails problem. It receives start and end point coordinates on a chess board, and must return the shortest path from start to end. ...
3 votes
1 answer
82 views

Exceeded time limit on Trie search with Backtracking using Swift

I have been trying to solve Trie related problems over at leet code and came across this interesting problem 211. Design Add and Search Words Data Structure Here is the question for convenience: 211. ...
1 vote
1 answer
65 views

Parsing an XML tree of categories

I have parse function which is parsing tree of categories. I've written it in simplest way possible and now struggling with refactoring it. Every nested loop is doing the same stuff but appending ...
  • 21
2 votes
1 answer
75 views

Find all non-crossing tuples which has the same content with a given tableau

Let T be a semistandard Young tableau of rectangular shape. For example, [[1,2,4],[3,5,6]] is such a tableau, where [1,2,4] and [3,5,6] are columns. All non-...
3 votes
1 answer
104 views

generate combinations from list of numbers

generate all combinations from list of numbers,the combinations can be pair of two numbers example 1 : list of 2 numbers [1,2] [ [[1],[2]], [[1,2]] ] example 2 : ...
4 votes
1 answer
63 views

Optimising compatibility-conflict graph solution - python recursive routine

Background I'm implementing an algorithm which localises overlapping sound sources using the time-difference-of-arrivals across 3 sensors [1]. Compatible 'triples' (e.g. with only 2 common sensors) ...
  • 143
5 votes
2 answers
1k views

Get two closest numbers in a list using recursion in python

I'm trying to use recursion to find the closest numbers in a list. I made a program that runs correctly without any errors but I want to know if there's a better way to write my program while still ...
1 vote
0 answers
34 views

Iterate tables from table id from href links until no table with specific table id is found

I am doing web scraping to the next web page (which is my root URL to start scraping tables): https://www.iso.org/standards-catalogue/browse-by-ics.html What I am trying to achieve is to parse the ...
  • 11
2 votes
0 answers
49 views

Recursive path drawing in Latex

I have some diagrams I'm drawing using tikz and I'd like to make a macro to draw them for me. I will describe it fully but here are some examples so you can follow along: The diagram has a number of ...
2 votes
1 answer
115 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 ...
1 vote
0 answers
580 views

Recursive combinations with subsets in Elixir

...
  • 111
2 votes
1 answer
43 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 ...
1 vote
1 answer
106 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, ...
2 votes
1 answer
80 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. ...
0 votes
1 answer
153 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 ...
0 votes
0 answers
117 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 ...
2 votes
2 answers
184 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 ...
  • 21
0 votes
1 answer
43 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, ...
  • 1
0 votes
2 answers
196 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 ...
0 votes
2 answers
774 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 ...
4 votes
2 answers
170 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 ...
0 votes
1 answer
77 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 ...
1 vote
0 answers
290 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 ...
1 vote
2 answers
316 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. ...
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 ...
2 votes
1 answer
70 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 ...
4 votes
1 answer
71 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
2 answers
81 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
1 answer
547 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 <...
4 votes
0 answers
543 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
2 answers
197 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 ...
  • 3,768
1 vote
0 answers
60 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 ...
  • 11
3 votes
0 answers
86 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 ...
  • 3,768
2 votes
2 answers
153 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. ...
  • 602

1
2 3 4 5
23