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.
2
votes
0answers
25 views
Recursion task - optimization
I need your review and suggestions how to make this code better. I'm just learning recursion and sure that this solution is not ideal.
Question:
Write a function that given an input array of ...
1
vote
0answers
14 views
Python: Recursion Practice
Problem:
Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.
sub_sandwich("catcowcat", "cat") → 9
...
0
votes
0answers
16 views
Recursive function to copy over an object with very specific constraints
I totally suck at recursion. I have a function that works but it also looks horribly wrong. I would love to 1) Know how to write it properly 2) Know about resources to read/study so that I don't get ...
0
votes
0answers
33 views
Attempting to obtain recursive web data-mining using an external file in Perl [on hold]
Question
I am looking for a way to modify my current "Script" to read an array, as a list in a text file (each hyperlink separated by returns within the same file, as seen in the "Additional Info" ...
2
votes
0answers
16 views
1
vote
1answer
18 views
Binary Search Tree insert while keeping track of parent for node to be added - iteration 2
Follow up question to
Binary Search Tree insert while keeping track of parent for node to be added
I am implementing a red black tree for fun and am wondering how I should modify my basic BST ...
0
votes
1answer
19 views
Binary Search Tree insert while keeping track of parent for node to be added
This question has a follow up question:
Binary Search Tree insert while keeping track of parent for node to be added - iteration 2
I am implementing a red black tree for fun and am wondering ...
3
votes
1answer
92 views
Tail-recursive call vs looping
I'm developing a poker app. It is almost done, and I'm looking for improvement. One of the things I wonder is whether I should change how I perform iterations. Currently I iterate by using ...
2
votes
1answer
40 views
Basic JSON Representation in Rust
This week I started reading "The Rust Programming Language". As I reached the chapters on enumerations and pattern matching I felt I had enough material to put together a simple representation of JSON ...
5
votes
2answers
45 views
Making the same amount from different combinations of coins (top-down approach)
I was reading a typical interview question found here. Given an amount and a list of denominations, count the number of possible ...
2
votes
0answers
47 views
Generate Subsets Of K Elements From A Set Of Strings
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'}
...
2
votes
1answer
70 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
41 views
Reversing all nested sequences
I'm writing a function that returns all (nested) sequences reversed:
...
2
votes
1answer
69 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 ...
-2
votes
2answers
61 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
55 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
98 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
31 views
1
vote
4answers
104 views
7
votes
1answer
68 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
66 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
520 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 ...
-7
votes
1answer
60 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
37 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
94 views
Finding the max sequence finder
Problem Statement
Find the max sequence finder.
findMaxSequence([3, 2, 3, 4, 2, 2, 4]);
...
3
votes
0answers
41 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
90 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
115 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
79 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
92 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
125 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
74 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
104 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
110 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
205 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
100 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
142 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
223 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
53 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
53 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
34 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
132 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
180 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 ...