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

2
votes
2answers
56 views

A set of names and a request with asterisks

I have a set of names and a request with asterisks. An asterisk can be replaced with any letter. For example, there is a set of names: hasad, ahmed, fizo. And there are a few sample requests: hasad, ...
-2
votes
0answers
23 views

Recursive function calls with same parameters [closed]

I have a function "CALLER" which gets some variables from the application and then passes to a recursive function "CALLED". Some of these these variables are same for all the recursive calls to ...
4
votes
2answers
387 views

Non-recursive method for finding a ^ n

I am working on an interview question from Amazon Software. The particular question I am working on is "to write a program to find an." Here is my recursive solution to this problem (in Java): ...
0
votes
2answers
65 views

Using recursion to count nodes in a binary tree, test equality of linked lists, and find extrema of a linked list

I am working with a some small functions to test recursion. I am fairly new to Python and am wondering if there is a cleaner way to get the job done. ...
3
votes
1answer
46 views

Grid walk problem and solving it recursively

On CodeEval, there's a Grid Walk challenge: There is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the ...
2
votes
2answers
68 views

Pascal's triangle in PHP

Are there any optimization suggestions? ...
1
vote
2answers
73 views

Reverse linked list using recursion

Here is my code to reverse link list in using recursion: ...
0
votes
1answer
46 views

Recursive Brute-Force [closed]

I have to recursively solve the following problem, using a brute force approach: Suppose two people, A and B, have an even number of ordered boxes, each with a given value. For example, ...
4
votes
3answers
80 views

Condensing code that generates Pascal's triangle

I recently started learning Java for a class and my teacher gave us an assignment in which we had to write up code which would print out the Pascal's triangle to an amount of rows decided by the user, ...
2
votes
2answers
59 views

Given a digit sequence, print the possible decodings of the given digit sequence

Examples: 12 gives: 'AB' and 'L' and 123 gives 'ABC', 'LC' and 'AW' Here is my attempt: ...
3
votes
2answers
96 views

Recursive functions for sorting

I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code: ...
11
votes
4answers
1k views

To understand what recursion is, you must first understand recursion

This is the second assignment for my CS2 course: Write a recursive C++ function writeLine() that writes a character repeatedly to form a line of n ...
5
votes
1answer
81 views

Paint fill function

Implement the "paint fill" function of image editing programs: Given a screen point and new color fill the surrounding area. Any comments on the code below? Time complexity: ...
1
vote
1answer
42 views

Find free username based on schema

Hopefully this is not too complicated. I have this code that will generate a username based on the pre-configured schema the admin types in. The fields they can use are: ...
7
votes
1answer
495 views

An Army of Ones

I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it? Challenge: ...
2
votes
1answer
32 views

Find relative filenames recursively in Emacs

I have a set of directories. For each directory I have a set of relative file names. I would like to select any of these relative filenames using completion, and then later reconstruct the absolute ...
5
votes
4answers
414 views

Digital root recursive function

Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following? This is also my first time using JUnit, I'd ...
3
votes
1answer
73 views

Walk a directory tree recursively

Any suggestions are welcome. ...
5
votes
3answers
131 views

Tree structure with support for inorder and preorder traversal

I am learning Tree Data Structures and came up with this code for implementing basic Tree Node using class and performing various Tree based operations like Traversals and others. The code works ...
0
votes
0answers
26 views

Optimize CSS Rule Dumper

I have written the following Tampermonkey/Greasemonkey script. I am trying to obtain a list of all CSS rules for a page; across all stylesheets. As of now, I am just iterating over everything. Is ...
5
votes
4answers
401 views

Recursive Java Red-Black Tree

I've made an attempt at a recursive Red-Black tree in Java. I realise that some of my code could be condensed but I tried to favour readability with this code as Red-Black trees can be somewhat ...
1
vote
1answer
61 views

How can I reduce this code javascript code so it's not as repetitve?

I have a function which goes through every name in an object. This object has an array parameter materials which holds other objects. Those objects have the same array parameter which hold more ...
3
votes
0answers
41 views

Spiral Scanning for matrix using recursion

I have written code for scanning an N x M matrix in spiral order using a recursive function. It uses 5 parameters - including 2 extra variables: call to keep ...
1
vote
0answers
68 views
5
votes
2answers
178 views

Knight's Tour with Heuristics

When someone suggested that I solve Knight's Tour, I did so with heuristics and recursion. It takes a lot of time to solve even a 8x8 board: N-A1 N-C2 N-E1 ... N-E6 N-F4 Time ...
12
votes
3answers
208 views

N-Queens - Brute force - bit by bit

A discussion in The 2nd Monitor made me realize I had never 'solved' the N-Queens problem. Additionally, as I read up on it, I realized that the 64-squares in a chess board would work well if ...
6
votes
1answer
142 views

Project Euler #14 — longest Collatz sequence

I was reading this question and realized that I didn't know Python well enough to critique the algorithm. So I wrote a Java solution instead, which is inappropriate for that question. Since there's ...
1
vote
2answers
45 views

Parse a tree & return the various paths

Input: { 1: [2,3], 2:[4], 3: [5,6], 4:[6] } Expected output: [[1, 2, 4, 6], [1, 3, 5], [1, 3, 6]] My Code: ...
4
votes
2answers
124 views

Importing different type of files into Lists

I am using a recursive directory scan to find all objects inside a Unity3D project. After that, I wish to move all these files to a sorted List. Is there a cleaner ...
2
votes
1answer
87 views

A prime number sieve using recursion

Out of curiosity, I built a recursive Sieve of Eratosthenes in Python and I was wondering how it could be improved for efficiency and how it can improved to be aligned with python best practices. ...
6
votes
1answer
43 views

'Tis the season for gift-wrapping

When reviewing a Graham scan convex hull algorithm implementation, I wrote the following function in an answer: ...
1
vote
0answers
40 views

AI for an online contest

I'm actually creating an AI for the online contest Vindinium. The fact is that's also an exam for my school because I'm going to have a note with that work. I created an AI based on ants pheromones ...
12
votes
2answers
190 views

My recursive parser is wet behind the ears (well, it's not DRY at least)

I have an issue opened on GitHub since mid-November, to refactor & DRY up the Rubberduck Parser module (the idea is to model the code in a VBA project or code ...
7
votes
4answers
422 views

Calculating a specific entry in a Pascal’s triangle recursively

Our task was to calculate the entry of a Pascal’s triangle with a given row and column recursively. The triangle was specified in a way that the tip of the triangle is ...
3
votes
1answer
108 views

Rotate image 90 degree clockwise recursively

Previous question: Rotate image 90 degree clockwise In this code I have used tail recursive, which is bad. Time complexity is still \$O(N^2)\$, which is worse-case. The only good part is memory ...
3
votes
1answer
53 views

Getting rid of extra test during initialization of loop/recursion

I'm reluctant to ask this question. My code below works, it's intelligible, and it seems reasonably efficient. It's just that there's a trivial, nitpicky issue that's driving me crazy. The function ...
5
votes
1answer
68 views

Create a tree recursivly

I want to create a Treeview in C# which will group file by prefix (here the prefix is a marked by the separator _). The following files should give this tree: ...
5
votes
2answers
166 views

Rotate an image (2D array) by 90 degrees recursively with low memory usage

I'm looking for comments on coding style, passing arguments, ...etc. ...
0
votes
1answer
66 views

Recursive functions

I am using the following code which recursively executes function findWpisInZone(), code works fine, I just wondering if there is any better way to do it in JS, ...
12
votes
2answers
213 views

Object storing and retrieving using wildcard identifier

I'm writing an interpreter for a scripting language which allows objects to: Have an alias Be referenced using a wildcard Contain child objects Combination of all three above For example: ...
2
votes
1answer
45 views

Memoization for calculating minimal traversal distance within a positive matrix

The code below is for calculating the minimal traversing distance from the top left point of the matrix to the bottom right point of the matrix. GitHub Here is the core functionality. Please note ...
1
vote
3answers
58 views

AudioMetaTagger: recursively read files and gather metadata

So the idea is to read metadata recursively in a chosen directory, load their metadata and display it into a table. Here is the simplified example of what I am doing. ...
2
votes
3answers
71 views

Removing nested blocks from a string

I wrote this function in scala that uses tail recursion to remove nested blocks from a text. Usage examples: ...
7
votes
2answers
205 views

Brainfuck interpreter in Haskell

Okay, so I just started learning Haskell around a week ago and this is my first real program that I worked on all of yesterday with a lot of help from IRC. I know that using indicies and arrays is not ...
6
votes
2answers
217 views

Merge sort using sentinels

This is my implementation of recursive merge sort, using sentinels: ...
7
votes
3answers
550 views

Simplifying this factorial function

def factorial(t,n): if n == 1 : return t else: x = (t * (n-1)) n = n-1 return factorial(x,n) print factorial(6,6) I can't seem to figure out ...
10
votes
2answers
274 views

Validating a Binary Search Tree

This is an implementation of a function to check the property of a Binary Search Tree, that is: the key in any node is larger than the keys in all nodes in that node's left subtree and smaller ...
2
votes
0answers
111 views

GOF Composite Design Pattern Implementation Using Modern C++

After reading about the composite pattern from the GOF design pattern book, I thought to re-implement the code mentioned in the motivation section using the modern C++ concept/idioms. Below is the ...
4
votes
4answers
267 views

Get the environment variable's value

I've written a function which can get the environment variable's value. The input parameter would one of the following: ${machine}/bin ...
4
votes
2answers
53 views

Lopsided Trees and Recursion

The original problem is: Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is ...