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

12
votes
5answers
1k views

Identifying first negative number in array of doubles

I was asked to create a function that checks if an array of doubles has all negative numbers or none. If these 2 (all negative, all positive) are false, check the first negative number, using ...
6
votes
1answer
146 views

Tower of Hanoi solver

Requesting code review, best practices, optimizations for this solution to the Tower of Hanoi problem. final class PlatePair { private final String source; private final String destination; ...
1
vote
3answers
101 views

To check if a string C is an interleaving of A and B Code

This is my code to check if a string C is an interleaving of Strings A and B. Please suggests optimizations, and where I can improve. #include <vector> #include <list> #include ...
12
votes
4answers
526 views

Displaying each number of an integer in a sequence

One of the books I'm currently reading to learn C# asked me to write a method that takes an integer between 1 and 99999 and displays each number in that integer in a sequence, separating each digit by ...
0
votes
1answer
19 views

Generic sequence splitter in Common Lisp

I wrote a function split-seq-by-n which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the remaining elements). It works on all ...
10
votes
6answers
550 views

Help refactor this to be less procedural and more recursive

Reference: Is this a faithful rendition of the selection sort algorithm? I'm working through an elementary book on sort and search algorithms, and writing some sample code to test my understanding. ...
6
votes
2answers
100 views

Is this non-recursive mergesort efficient and a good way to simulate the recursive version?

My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are: ...
5
votes
2answers
107 views

Optimize disk enumeration and file listing

I am writing C++ code to enumerate whole HDD and drive listing. However, it takes more than 15 minutes to complete the disk enumeration of all drives (HDD capacity 500GB) and compile the response in ...
2
votes
3answers
70 views

Python script to touch files of a particular pattern in all folders of a given name

The intent of this script is to hunt down all "*/testResults/*.xml" files and touch them, so that our build system doesn't issue errors that the files are too old (it's entirely intentional that tests ...
4
votes
3answers
78 views

Pair matching elements from two lists

Here is a method that takes two lists (l1 and l2) and pairs up elements that "match". As you can see at the end of the code block these lists consist of matching elements but in different indexes. The ...
4
votes
2answers
75 views

Recursive reverse function

Write a recursive version of the function reverse(s), which reverses the string s in place. Here is my solution: void reverse(char a[], int i, int j) { char tmp; if(i >= j) { ...
7
votes
3answers
96 views

Integer-to-string conversion using recursion

Adapt the ideas of printd to write recursive version of itoa; that is, convert integer into a string by calling a recursive routine Here is the implementation of printd: void printd(int n) { ...
-1
votes
1answer
48 views

Recursively calculating powers of numbers [closed]

In this program, I understood everything except power(x1,y1-1). I want to know how the power(x1,y1-1) function exactly works. #include<iostream.h> #include<conio.h> int ...
1
vote
1answer
41 views

replacing explicit recursion with a fold

as an exercise I wanted to rewrite this toy python code in haskell. def f(x): return abs(42-x)**2 def improve(x): newX = x + 0.1 return newX, f(newX) def optimize(f, goal): x = 0 ...
7
votes
1answer
123 views

Suggestions needed for alternative methods of solving sudoku

I am new to programming as well as this site. I am learning Java as my first programming language. I have written a bit of code (of course after struggling a lot). I would love to read expert reviews ...

15 30 50 per page