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

3
votes
1answer
31 views

Recursive Tic-Tac-Toe Solver in Python

I'm implementing a Tic-Tac-Toe solver in Python. It contains two functions: assess to determine whether a given board position is a win for either side, and ...
5
votes
2answers
47 views

Counting Increasing Subsequences of size K recursive

The original description of the problem can be found here, its input here and its expected output here. The problem: Given a integer sequence a1 ... an (-10000 \$\leq\$ ai \$\leq\$ 10000). ...
1
vote
2answers
47 views

Simple recursive function to find missing number in a permutation

This is a short and simple Python written to help me sharpen my dulling recursion skills. It expects a sorted permutation of integers n1..n2 in list format, with a single step missing (e.g., ...
3
votes
3answers
117 views

Reversing strings using recursion

I'm trying to solve exercises where I am required to use recursion. I wrote this: ...
2
votes
2answers
79 views

Beginner implementation of Merge Sort

This is my first time implementing a merge sort (just getting started with algorithms & data structures). Are there any obvious things I have done wrong? I am also worried that I have overused ...
4
votes
1answer
57 views

Merge sort implementation in JS

Just for learning and practicing I've created a completely recursive version of the merge sort algorithm. I've tested it a little bit and it seems working, but I'm quite sure that it can be largely ...
4
votes
5answers
148 views

Permutation of n lists

I have code which gives permutations for 10 lists. The code works fine for small number of lists with small number of values. Result : It should return all possible permutations. I have to store the ...
2
votes
1answer
39 views

Practicing recursion with getElementsByClassName

I'm trying to get a good grasp on recursion by implementing document.getElementsByClassName. I've made something that works but I'd like to know if there is some ...
1
vote
2answers
31 views

Inserting new Node in a Binary Search Tree

I wrote this method to recursively insert a new node at the proper position in a BST. Is it good enough? Can it be improved? It went through a couple of revisions and I still am not very confident in ...
4
votes
0answers
34 views

Selecting subset of size k using recursion

Sometimes I need to implement recursive algorithms that pass a certain state from one recursive call to another. For example, a greedy subset selection: we have a set of candidate objects, and we ...
3
votes
2answers
106 views

Generate URLs from a complex JSON object using recursion

My task is here as follows : Input : A complex/nested JSON object with nested arrays as well objects Output : A JSON object that contains a set of URLs with their titles: ( key,value ) ...
2
votes
1answer
51 views

Recursive Sudoku Solver

I just finished up a program which takes a byte[9][9] as input and recursively does a DFS to find any solutions (including multiple solutions). I'm pretty happy ...
3
votes
1answer
31 views

Recursively delete empty folders in Lua

I have written a script that run in WingFTP Server which has a Lua scripting engine built in. The script recursively deletes empty folders except the specified root folder. ...
6
votes
2answers
46 views

Recursively evaluate neighbors in a two dimensional grid

I'm creating a puzzle mini game where there is a board of gems, varying in color, and chosen at random. This is what my code generates: When you click on a gem the game should traverse the board ...
1
vote
1answer
65 views

Combining two sorted lists

I'm just hoping if there's a way to simplify this recursive code that takes 2 sorted lists and combines the two together in a sorted manner (without actually having to re-sort them). ...
5
votes
2answers
335 views

Recursively insert a node in an ordered Linked List

I've written this and it works great. Is there any shorter or simpler way to achieve the same result without distinguish between cases? ...
0
votes
0answers
59 views

Find the most efficient combination that equals target number in ArrayList

I want to implement the following function: Given a target sum, return the combination that equals the target sum and is the most efficiënt combination in the array of an ...
3
votes
1answer
57 views

Creating a menu as nested unordered lists from JSON data

I have a JSON input using which I have written below function to recursively create an unordered list. Is there more precise way to achieve it? ...
2
votes
2answers
35 views

Tail-Recursion to get a Map of word counts

I want to read a file and store the number of occurrences of each word in a Map, using tail recursion. I came up with the following; it seems to work; does it look like it's right? ...
2
votes
2answers
54 views

Algorithm that checks if a tree is full and complete

I am trying to write a method that will return true if a binary tree is full and complete (each node has 2 children or none and all the leaves of the tree are at the same depth). My idea is to use ...
8
votes
2answers
164 views

Let's Break Down the Party by Breaking the Party Down Recursively

This is a rags-to-riches an overdue alternative implementation on my previous question: Let's Break Down the Party This alternative uses the int internal ...
0
votes
1answer
29 views

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

I wrote BST insertion code with the book. The book uses recursion, but I just want to know how I can do it without recursion. My code is working, but I don't know if it is correct. ...
5
votes
3answers
226 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 ...
5
votes
1answer
80 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
41 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
116 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
65 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 ...
2
votes
1answer
40 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
381 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
191 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
23 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
60 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
112 views

A program to shred files

The following is a program to shred files securely: ...
3
votes
0answers
60 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
115 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
61 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
44 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
274 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
85 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
410 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
331 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
72 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
231 views

Pascal's triangle in PHP

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

Reverse linked list using recursion

Here is my code to reverse link list in using recursion: ...
0
votes
1answer
55 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
116 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
85 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
140 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
2k 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
129 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: ...