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

7
votes
4answers
156 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
55 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 ...
-2
votes
0answers
16 views

Recursive function calling another function [on hold]

I'm new to Python and I made this recursive function with a non-recursive function as one of its arguments. I was expecting it to print 4 times but never did. May I know what I'm missing? ...
3
votes
1answer
34 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
56 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
133 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
57 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, ...
8
votes
0answers
116 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: ...
1
vote
1answer
38 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
44 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
67 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
170 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
166 views

Merge sort using sentinels

This is my implementation of recursive merge sort, using sentinels: ...
7
votes
3answers
534 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
176 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
74 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
261 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
48 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 ...
6
votes
3answers
768 views

Reversing an array recursively

Implementation: ...
3
votes
3answers
145 views

Miller-Rabin Recursive Primality Test

I'm working on a primality test and have written a recursive function that returns the value of the function \$b^{q-1} \bmod q\$ where \$3<= q <= 32000\$ Is there any way to speed up ...
2
votes
1answer
266 views

Nsum problem: find all n elements in an array whose sum equals a given value

I am implementing the algorithm for the following problem with Python. I am pretty new to Python, so I want to listen to any advice that improve my coding style in a "pythonic" way, even about naming ...
4
votes
2answers
328 views

Simple factorial program using recursion

Two concepts I realized I needed to understand and use more are recursion and Exceptions. Thus, I combined both in the following program. Although it began with a focus on using recursion it became ...
4
votes
2answers
500 views

Building a simple tree structure

I'm trying to build this simple tree: ...
3
votes
3answers
262 views

Merge Sort - Efficiency

I've written this Java code to implement Merge Sort. ...
6
votes
3answers
256 views

Recursive linear search - branch style and layout

Is my layout of the if/else statement reasonable? It feels clumsy to me to spread the termination condition over the first three lines of the function. Can I ...
2
votes
1answer
55 views

Time complexity of 0/1 Knapsack challenge

The code gives correct output. How do I calculate time complexity for code like this? The program finds all the combinations of items and sees if the combination gives the max profit. If the last ...
1
vote
1answer
37 views

Decoding an element list

I have a function which I am calling an infinite number of times (or until a condition is met). The problem with this recursive function is that on a higher level, it is called by a worker thread ...
4
votes
1answer
884 views

Implement a string in reverse using pointers and recursion

I'm trying to reverse a string using pointers and recursion, and I send it a char array. Is this the best way, or is there a better one? ...
5
votes
3answers
293 views

Merge Sort Implementation in Java (that seems slow…)

I decided to write my own implementation of merge sort. Here is the code: ...
2
votes
1answer
104 views

Cutting stock recursion

This problem is identical to the one here: Suppose that you have been assigned the job of buying the plumbing pipes for a construction project. Your foreman gives you a list of the varying ...
2
votes
1answer
82 views

Tail recursive sort

I've heard of this implementation of quick sort (in pseudocode): ...
1
vote
2answers
115 views

Using brute force to find an energy optimal path for a given amount of time

The code below implements a brute force method to find an energy optimal path for a given amount of time t_aim using recursion (the recursion function is ...
2
votes
1answer
62 views

Process a line in chunks via Regular Expressions with Ruby

I'm writing a Ruby script to reverse engineering message log files. They come from an external system with the following characteristics: Each line of the log file has at least one message. Each ...
2
votes
1answer
48 views

Efficiently creating a menu consisting of multi-level structure

I was asked to modify existing code to allow multi-level page structure. Each page can have one parent, and one page can have multiple children. I will present following code. My question is is there ...
5
votes
1answer
1k views

Print all possible combinations of size r, from an array of size n

This is my working solution for the following problem: given an array of integers of size n, print all possible combinations of size r. Before I proceed to the solution, I have the following ...
11
votes
3answers
281 views

Recursive, nested list traversal

Given a nested list of strings (which may contain other nested lists), print the contents of the list and the corresponding depth. Here is my solution: ...
8
votes
1answer
88 views

Queens placement

The code below is intended to be a learning material for high school intermediate programming class, as an introduction to recursion and backtracking. I was thinking of rook placement and found it too ...
4
votes
1answer
1k views

Recursive function that generates the permutations of a string

I am looking for a review of my recursive function that generates the permutations of a string. Are there better ways to do this? ...
4
votes
1answer
56 views
2
votes
3answers
107 views
4
votes
1answer
71 views

Comparison of Fibonacci (Multinacci) Functions in Python3

After coming up with a formula on this Stack Overflow question, defeating recursion limits and finding a few new ways of calculating these numbers (as per this Stack Overflow question), I decided that ...
4
votes
0answers
67 views

Refactoring while-do array comparison function into tail recursion with F#

As part 2 of my other question concerning this long running project I've been inquiring about on CR, I reimplemented my generic function for determining if an array of arrays is a sub-array or ...
2
votes
1answer
78 views

Refactoring while-do into tail recursion with F#

I have a while-do loop nested inside a while-do loop in my program, due to it needing to iterate in two dimensions through an array of arrays, and originally my loop looked like this: ...
4
votes
3answers
125 views
3
votes
2answers
281 views

Alternate method of iterating than os.walk

Recently, I became tired of how slowly os.walk seems to run (really, it should be called os.crawl), and made something recursive ...
8
votes
3answers
446 views

Stock Pipe Cutting using Recursion

This problem is from the Stanford Open Course CS106B Programming Abstractions Assignment #3 Problem number 6 here. "You are charged with buying the plumbing pipes for a construction project. Your ...
4
votes
1answer
55 views

Recursive Django filter to output a list from user hierarchy

I need to create an HTML unordered list (to display with jstree) to display the hierarchy of users, along with a list underneath the user's "subusers" of their comments. Each user could have many ...
2
votes
1answer
43 views

Slow calculation of trigonometric sine function

Background Creating a client-side pie chart in XSLT 1.0, without extensions or external dependencies (i.e., cannot use FXSLT, EXSLT, JavaScript, etc.). Problem The code is slow; at least fifteen ...
3
votes
1answer
47 views

Erlang pattern matching excersise

I recently started my first project with Erlang. I've been skimming documentation and various books to get the information I need, and it's going well, but now that I have something that works I want ...
11
votes
3answers
207 views

Algorithm to calculate semi perfect integers, lack of efficiency

I'm working on an algorithm to calculate weird numbers, and to do so there are several properties that needs to be calculated, one of them being, if it is NOT a semi-perfect/pseudoperfect number. My ...