recursion

Basic C++ Recursion program questions

//This program finds the GCD of two numbers using a recursive function call via the //Euclidean algorithm #include <iostream> #include <cmath> using namespace std; int GCD (int A, int B); int main() { int A = 45, B = 55; cout << "The GCD is " << GCD(A,B) << endl; //test return 0; } int GCD (int A, int B) { A = ab...

Recursive CreateDirectory

I found many examples of CreatingDirectory recursively, but not the one I was looking for. here is the spec Given input \\server\share\aa\bb\cc c:\aa\bb\cc USING helper API CreateDirectory (char * path) returns true, if successful else FALSE Condition: There should not be any parsing to distinguish if the path is Local or...

Recursive Fibonacci

I'm having a hard time understanding why #include <iostream> using namespace std; int fib(int x) { if (x == 1) { return 1; } else { return fib(x-1)+fib(x-2); } } int main() { cout << fib(5) << endl; } results in a segmentation fault. Once x gets down to 1 shouldn't it eventually return? ...

Help with Recursive SQL

I have a category table similar to this: uid | ParentLevel | ParentID | Name ------------------------------------ 1 | 0 | 0 | foo 2 | 1 | 1 | blat 3 | 1 | 1 | baz 4 | 2 | 3 | blah 5 | 0 | 0 | bar I am trying to get ...

Recursion Tree, Solving Recurrence Equations

As far as I know There are 4 ways to solve recurrence equations : 1- Recursion trees 2- Substitution 3 - Iteration 4 - Derivative We are asked to use Substitution, which we will need to guess a formula for output. I read from CLRS book that there is no magic to do this, i was curious if there are any heuristics to do this? I can certa...

How to find all available maze paths?

I am trying to write a program that is given a maze and tries to find the way out. M is the entrance, E is the exit, 1s are walls, and 0s are pathways. It is supposed to find each path and put P in the path. It is supposed to find all available paths. Right now it finds part of a path. Here is the code: public class Maze { private...

Failure to recurse

I have written a recursive function. For some reason it just won't call itself after it has run through for the first time. It just takes the next item from the loop without going down deeper. I am using Visual Studio 10, and am lacking sleep. public IEnumerable<string> GeneratePath(int depth) { int presentDepth = depth; char c...

regex - find specific text between 2 specified boundary

Hi, I'm trying to develop a regex that will detect recursive template calls in an xsl style sheet. So far, it has not been really successful. In the following code, I need to detect that template B is called recursively: <xsl:template name="A"> blah blha ?!@#?%$#^%?*?&(({}:"><;'[]\/.,./' <xsl:call-template name="B"> b...

Recursive function best practices; What are they?

Hello, What are some other language independent ways of designing recursive functions other than the typical: if (counter < 1) return output; else callSelf(); Do other methods even exist? Whenever viewing examples I always see a version of the code above. Thanks! :) ...

Should I learn recursion before OOP?

I am reading this C++ book, "Problem Solving with C++" in my free time. I have gotten through 4 chapters, and now I am at a split. I can either go to chapter 5 which is file operations and an introduction to OOP, or I can go to chapter 12 which is recursion. So far I have only gone over compiler basics, all that if, else, and loops synta...

Why are pointers and recursion looked upon as an complicated issues ?

Hi, Recently I was reading about Article on Interviewing an Software Engineering Position by Joel and he mentioned about asking candidate about Recursion and Pointer's after some simple puzzles. I wonder why Pointers and Recursion are considered to be complicated Issues ? Update: What can be done to improve on Pointers and Recursion...

Recursion and return Dates in C#

Hello, I can't get this method to return the right date. What this method does is take the current date and add the amount of days you specify. So if you want the next Monday, it'll return the next Monday. It also sends the date into a method that checks to see if it's one of the "Filtered Dates" that aren't allowed to be returned. This...

Stack Overflow After 15 Recursions with Javascript Class Function

I have the following code sample to illustrate my point. When I load this in IE8 on Vista I get the error "Stack Overfow at line:16" If I recurse using a top level function (outside of the testClass object) I can recurse millions of times without a stack overflow. Why is this happening? Ultimately I just implemented a Function Que ins...

C# implementation of deep/recursive object comparison in .net 3.5

I am looking for a C# specific , open source (or source code available) implementation of recursive, or deep, object comparison. I currently have two graphs of live objects that I am looking to compare to each other, with the result of the comparison being a set of discrepancies in the graphs. The objects are instantiations of a set of ...

Dynamically scoped variable in java ? (a.k.a one variable per method execution)

hi, I would like to know if it's possible in java to declare a variable local to the execution of the method. For instance, if i'm doing some recursive stuff and i want to keep various counters specific to one particular execution of the method. I don't know the correct english expression for that... ...

Java How to find a value in a linked list iteratively and recursively

Hi I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; public ListNode next; } Then, the metho...

Xpath in XSLT: select elements that are between 2 other elements, part II

As similar to this question (there are more related entries, however as a new user I can only post one URL): http://stackoverflow.com/questions/1489326/xpath-get-elements-that-are-between-2-elements I have a question regarding the selection of set of elements that occur between 'other / delimiting' elements. This situation occurs when t...

Design patterns for converting recursive algorithms to iterative ones

Are there any general heuristics, tips, tricks, or common design paradigms that can be employed to convert a recursive algorithm to an iterative one? I know it can be done, I'm wondering if there are practices worth keeping in mind when doing so. ...

Appending an integer to a List in Ocaml

How can i implement this function? let rec append l i = (* For example, if l is a list [1;2] and i is an integer 3 append [1;2] 3 = [1;2;3]*) ;; ...

XSLT - how to parse xml with recursive elements to Eclipse toc.xml?

Hi, I have the following XML: <HTML> <HEAD> <META name="GENERATOR" content="Microsoft HTML Help Workshop 4.1" /> <!-- Sitemap 1.0 --> </HEAD> <BODY> <OBJECT type="text/site properties"> <param name="FrameName" value="contents" /> </OBJECT> <UL> <LI> <OBJECT type="text/sitemap"> <pa...