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

4
votes
1answer
50 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
143 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
27 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 ...
0
votes
0answers
62 views

Knapsack Algorithm and Recursion - MATLAB [closed]

I have a problem with my knapsack algorithm. The problem is about adding files to the storage and maximizing the computing time. Of course, there is a capacity limitation. The problem is that I can ...
4
votes
0answers
24 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
101 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
27 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
43 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
59 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
319 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
54 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
43 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
30 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
53 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
27 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
221 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
74 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
39 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
111 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
59 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
38 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
378 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
183 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
17 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
58 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
50 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
113 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
58 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
43 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
259 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
84 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
407 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
284 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
70 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
184 views

Pascal's triangle in PHP

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

Reverse linked list using recursion

Here is my code to reverse link list in using recursion: ...
0
votes
1answer
54 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
111 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
80 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
136 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
123 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
37 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
489 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 ...