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.

learn more… | top users | synonyms

-1
votes
0answers
18 views

All Subsets Of A Given Set Of N Words C# [on hold]

This is the task: Write a recursive program, which prints all subsets of a given set of N words. Example input: words = {'test', 'rock', 'fun'} Example output: (), (test), (rock), (fun), ...
2
votes
1answer
60 views

Recursive function application

I use a lot T4 templates and want to avoid extra code writing when it could be generated. Currently I have following class: ...
2
votes
1answer
25 views

Reversing all nested sequences

I'm writing a function that returns all (nested) sequences reversed: ...
1
vote
0answers
36 views

Find all the countries I can visit by just crossing direct borders

I was helping on this question. There you have a table border to indicate countryA and countryB have a common border. And want ...
-1
votes
0answers
32 views

Given a path to a directory, print the path to the biggest file in it - revision 2

The problem description is in the title. Revision 1 I followed the suggestions from this answer. In this revision: if (files != null) is used instead of ...
-2
votes
2answers
55 views

Recursive function in JS

EDIT: The code i provide includes a asynchron task in each interation, therefor i need the recursive function, my question is how to beautify the code and apply the proper use. I want to: Remove ...
6
votes
2answers
40 views

Perl recursive copy and move functions

I know a module like this already exists on CPAN, but I wanted to write my own simplified version that accepts wildcards in the input. I don't write many Perl modules so I figured I would post the ...
4
votes
2answers
103 views

Given a path to a directory, print the path to the biggest file in it

Here is my code. I simulated a stack rather than used some regular recursive algorithm because I needed to keep track of two variables: the path to the biggest file and its size. Besides I wrote a few ...
7
votes
1answer
84 views

Path finding algorithm using recursion in Python

Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal. In the maze defined, ...
2
votes
1answer
29 views
1
vote
4answers
99 views

Negative factorial in JavaScript

I was doing a basic problem on coding a factorial \$n!\$: ...
7
votes
1answer
50 views

Recursive program for generating and printing all permutations of the numbers 1, 2, …, n for given integer number n

I've just written code for generating all permutations of the numbers from 1 to n in Java. It seems to work, but I think it's a bit more complex than it needs to be. ...
6
votes
1answer
63 views

Pick sequences of numbers to maximize the points

It is a single-player game. In the beginning, there is a row of integers. In one move the player can take a certain amount of adjacent numbers (let's denote it T). Then the player's points increase ...
7
votes
3answers
463 views

Check if 2 arrays have (exactly) the same elements recursively

I've been given a homework assignment to make a function to check whether 2 given arrays with the same given size have exactly the same set of elements. My function seems to be working but I feel ...
-6
votes
1answer
54 views

Counting number of steps while finding right path [closed]

I am writing a code which would return the path in a maze using recursion, but now with the path I also want the number of steps. How do count number of steps in this program? or number of times ...
2
votes
0answers
36 views

Recursive implementation of integer partition without re-arrangement

Problem: Integer partition without re-arrangement Input: An arrangement S of nonnegative numbers {s1, . . . , sn} and an ...
4
votes
4answers
87 views

Finding the max sequence finder

Problem Statement Find the max sequence finder. findMaxSequence([3, 2, 3, 4, 2, 2, 4]); ...
3
votes
0answers
36 views

Recurse on complex Perl data structure, applying needed rules

Inspired by this answer and previous a commentator of code review use: Given a complex Perl data structure, traverse/jigger/modify as follows: If ORACLE_SID is ...
17
votes
4answers
4k views

Print the Twelve Days of Christmas without loops or conditionals

For my AP Computer Science class, I am required to write a program that prints the Twelve Days of Christmas without loops or conditionals using static methods. ...
3
votes
2answers
88 views

A “map” function that alternates between two mapping functions

I am trying to solve following problem in Haskell using recursion: Define a recursive function funkyMap :: (a -> b) -> (a -> b) -> [a] -> [b] ...
2
votes
2answers
113 views

Code optimization of recursive function

I have a mathematical function as shown below $$ (h+1) * U(k,h) = \sum_{r=0}^k \sum_{s=0}^h (r + 1) * (k - r + 1) * U(r + 1, h - s) * U(k - r + 1, s)\ + \sum_{r=0}^k \sum_{s=0}^h (k - r + 1) * ...
6
votes
2answers
106 views

A recursive program that attempts to solve an extremely large number

This is my recursive program for the following function: \$F(x) = G(x) - W(x)\$ \$G(x) = [G(x-1)+G(x-2)]^2\$ \$W(x) = [W(x-1)]^2 + [W(x-2)]^2\$ If x == 0 in either function G or function W, then ...
6
votes
1answer
67 views

Function that recursively downloads entire directory is slow

I created this function to recursively copy an entire directory from an FTP server. It works just fine except that it is about 4 times slower than using FileZilla to do the same operation. It takes ...
4
votes
1answer
70 views

Powershell zip subfolders recursively, conditionally

This is a progression of the script I posted here: Zip the contents of subfolders, conditionally It does this: Determines all subfolders recursively Checks each subfolder for files older than 31 ...
7
votes
1answer
121 views

Finding permutations of a word

This was a basic anagram problem. Take an input word, find all its permutations, then check a dictionary file to see what if any of those are real words. Dictionary file My input data: ...
7
votes
3answers
72 views

Running a script recursively in subdirectories

I got tired of running the same command in multiple directories, so I thought "there has to be a way to make this easier". The commands I was running was mostly ...
6
votes
2answers
95 views

Web Scraper in Python

So, this is my first web scraper (or part of it at least) and looking for things that I may have done wrong, or things that could be improved so I can learn from my mistakes. I made a few short ...
4
votes
1answer
102 views

Recursive, depth first search

I wanted to write a function findDeep that would perform a recursive, depth-first search on plain objects and arrays. Comments and criticism welcome. ...
7
votes
2answers
192 views

Sudoku Solver in C++ weekend challenge

I am very new to programming (using C++) and coded a sudoku solver as a weekend challenge. I guess there are so many things to criticize, but I would really appreciate some constructive criticism. ...
5
votes
2answers
96 views

Binary Search tree deletion optimization

I have just started implementing Binary Search tree on my own without using any tutorials online. Please have a look and suggest how can I make code less cluttered and more faster. Right now I am ...
5
votes
2answers
134 views

An implementation for the double factorial

I have written this piece of code that implements the double factorial in Python both iteratively and recursively; the code works without problems, but I'm interested in improving my overall ...
1
vote
0answers
23 views

Recursively merge objects with corresponding property names

I have such objects that I need to merge: ...
4
votes
3answers
215 views

Python function to determine whether a given BST is valid

Here's a simple function I wrote using recursion. Does this run in \$O(n)\$ time and use \$O(n)\$ space, where \$n\$ is the number of nodes in the tree? ...
1
vote
3answers
91 views

Finding the longest common suffix recursively

I'm getting the correct results, but my method isn't the prettiest. Is there any way to do this with less code? ...
5
votes
1answer
52 views

Using generators to build up a maze

In prepping to teach a workshop on recursion I wrote this code that uses a maze-building algorithm. In doing so I found it really natural to use generators a lot. I feel pretty happy with how the code ...
1
vote
1answer
49 views

Zip the contents of subfolders, conditionally

I've written a script in Powershell for zipping files into new folders. This script performs the following steps: Check whether each subfolder contains non-zip files which are older than 31 days If ...
12
votes
5answers
1k views

Simple Fibonacci using recursion

The sole purpose of this post is to see how a production quality developer would approach this very simple problem. I am a fresh graduate and do not have a professional development experience. What ...
2
votes
0answers
33 views

Parallel Multiplier: an implementation of `RecursiveTask<V>`

This class is my attempt at creating a re-usable class that simplifies the parallel calculation of products. I would appreciate hints on all aspects especially the value of the threshold for which the ...
7
votes
1answer
129 views

“Dungeon Game” solution

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was ...
2
votes
2answers
148 views

Check if a binary tree is a binary search tree

Given a binary tree, I need to check if it satisfies the binary search tree property i.e. left child is less than or equal to the current node and right child is greater than or equal to the current ...
4
votes
1answer
155 views

Counting ways to fit bottles in crates

I'm calculating how many possibilities there are to fit \$n\$ identical bottles inside \$k\$ crates of various capacities. n = Number of bottles k = Number of crates K = List of the number of ...
2
votes
2answers
146 views

Non-Contiguous Substrings

Problem: A non-contiguous substring of string \$s\$ is a sequence of \$k \geq 0\$ characters in \$s\$, in the order in which they occur in \$s\$. For instance, the set of all non-contiguous ...
7
votes
4answers
240 views

Add one to a very large integer

I was asked to implement this in an interview a while back. I didn't pass the interview, mostly likely because it took me far too long to do. However, I'm interested to know how well implemented the ...
2
votes
4answers
490 views

Binary tree from given Inorder and Preorder traversal

This builds a BinaryTree from given Inorder and Preorder lists. ...
5
votes
1answer
42 views

Report with Subtotals — In Search Of An Abstraction

High Level Explanation of Code's Purpose I wrote a class to create sectioned reports, where each section has a subtotal. It allows these reports to be nested within each other, to create multiple ...
4
votes
2answers
71 views

Calculating the number of elements of an underlying data structure

I read many comments on this question that one really shouldn't use local classes for functionality like which my code provides, but I couldn't really put things into perspective and decide what ...
0
votes
1answer
149 views

Operating on a list of files using recursion

I'm starting just now with CoffeeScript and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve the code that I just wrote using built-in ...
1
vote
1answer
287 views

Ackermann Function of (4,2)

How efficient is this program? How could I make it more efficient? ...
1
vote
1answer
69 views

Reversing a linked list recursively

This appears to work. Are there any edge cases I am missing? What are your thoughts on the algorithm and implementation? ...
3
votes
1answer
83 views

Merge Sort - Using Ruby and Recursion

I am implementing the algorithms of Course: Coursera Algorithm I. I implemented the Merge-Sort using recursion and although it sorts correctly I am not sure if it is a correct implementation of this ...