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

0
votes
1answer
11 views

Adding a node to a Binary Search Tree and printing the path to it

I write the code BST Insertion with book. The book is written by using a recursion. but I just want to know that Not using a recursion. So here is my code. It is working. but I don't know It is ...
0
votes
0answers
27 views

Schedule AI Challenge: recursive function crashes browser [on hold]

I am doing the 'schedule' AI challenge and worked a lot on producing the code below. It works great for the Easy test (10 courses), but crashes the browser on the Harder one (250 courses). I suspect ...
5
votes
3answers
204 views

Using recursion to count substrings (with exceptions to the rule) in Java

I am going through the CodingBat exercises for Java. Here is the one I have just finished: Given a string, compute recursively the number of times lowercase hi ...
-3
votes
0answers
25 views

Recursion java program [closed]

Write a method printNumDots() to print an ascending sequence of integers beginning from 1, each followed by dots as many as the preceding integer. For example, printNumDots(6) shall print 1. 2.. 3... ...
5
votes
1answer
63 views

Test file word cloud in F#

This code is meant to take in a command line argument and output a 'tag cloud'. It's more of an exercise in learning F# for me because this is my first non-tutorial code file. How could this code be ...
1
vote
2answers
32 views

Basic functions (sum, len, etc.) with recursively-flattened arguments

Based on the excellent answers provided for my previous question, I've thoroughly revised my attempt at "deep" versions of all, ...
5
votes
2answers
90 views

Consecutive Primes challenge at CodeEval.com and memory allocation issue

I finally solved this challenge with using recursion and figured out why the automatic scorer wasn't passing my previous solutions. I was using NSMutableArray to ...
4
votes
0answers
33 views

Recursive flattening of Swift sequences

In Flatten to get all child controls of certain type in a UIView, methods were discussed to recursively flatten a tree-like structure in Swift, resulting in an array of all elements. Motivated by ...
1
vote
1answer
31 views

Palidrome checker in haskell

I decided to avoid the trivial isPalindrome lst = lst == reverse lst and tried writing a method with pattern matching and recursion. ...
6
votes
3answers
368 views

Deep/recursive join, all, any, sum, len

I keep forgetting that the standard join() can only take a single iterable, so I made a few functions that act recursively on any passed arguments. Somewhat ...
3
votes
2answers
170 views

Recursive math expression eval

It has been very hard to use recursion, but I think that it made the code shorter and cleaner. ...
1
vote
0answers
12 views

Recursive way to find Inorder successor

So far I have attempted to find the inorder successor through recursion and it seems to be working right. Can someone review the below code and give suggestions. ...
1
vote
1answer
55 views

Is this the best way to check sorting (in recursion) without loops?

Please let me know if there is a shorter way to do it again without any kind of loops. Recursion only. ...
3
votes
2answers
109 views

A program to shred files

The following is a program to shred files securely: ...
3
votes
0answers
39 views

Print the nodes of binary tree column-wise, using recursion and iteration

I am trying to code for both recursive and iterative approach to a problem. Below is a recursive code to print the nodes of binarytree column wise. Basically I have count of root as 0 and if I move ...
4
votes
3answers
109 views

Directory Snapshot

The following code creates a recursive backup of a directory in the form of interlinked HTML files, structured in the same form as the input directory. It does not take the backup of the contents ...
1
vote
2answers
49 views

Forming combinations of a 16 bit binary number

I wrote this code to form combinations of a 16 bit binary number (I know it is in output is string format, but it is my goal to just print all possible 16 bit binary numbers). My question is, can this ...
3
votes
2answers
40 views

Recursive file copy function

I created this function and I'm unsure if it is sufficient for "real world use", because all code snippets on the net I found for recursive copy functions used functions like ...
10
votes
1answer
247 views

Arranging 8 queens on an 8x8 board

Print all the ways of arranging eight queens on an 8x8 board. Rules: Queens should not share the same row, column, of any diagonal. Any comment on my solution? I didn't write unit tests but I ...
2
votes
2answers
81 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, ...
4
votes
2answers
400 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
194 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
65 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
132 views

Pascal's triangle in PHP

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

Reverse linked list using recursion

Here is my code to reverse link list in using recursion: ...
0
votes
1answer
51 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
100 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
74 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
105 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
107 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
46 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
498 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
36 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
464 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
115 views

Walk a directory tree recursively

Any suggestions are welcome. ...
5
votes
3answers
272 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
34 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
531 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
62 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 ...
5
votes
2answers
82 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
86 views
5
votes
2answers
235 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
328 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 ...
7
votes
1answer
269 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
52 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
151 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
166 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
46 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
43 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 ...