recursion

Recognizing Tail-recursive functions with Flex+Bison and convert code to an Iterative form

I'm writing a calculator with an ability to accept new function definitions. Being aware of the need of newbies to try recursive functions such as Fibonacci, I would like my calculator to be able to recognize Tail-recursive functions with Flex + Bison and convert code to an Iterative form. I'm using Flex & Bison to do the job. If you hav...

Non recursive way to position a genogram in 2D points for x axis. Descendant are below

I currently was tasked to make a genogram for a family consisting of siblings, parents with aunts and uncles with grandparents and greatgrandparents for only blood relatives. My current algorithm is using recursion. but I am wondering how to do it in non recursive way to make it more efficient. it is programmed in c# using graphics to dr...

Recursion Question : Revision

My slides say that: A recursive call should always be on a smaller data structure than the current one There must be a non recursive option if the data structure is too small You need a wrapper method to make the recursive method accessible Just reading this from the slides makes no sense, especially seeing as it was a topic from be...

What is this kind of mutual "recursion" called?

My issue is with a certain style of code that very much resembles recursion, but isn't quite that. Recursion is, to quote Wikipedia, "a method of defining functions in which the function being defined is applied within its own definition". Similarly mutual recursion applies another function which, directly or indirectly, applies the func...

Sequential numbering from recursive function? e.g. 2, 2.1, 2.1.1, 2.2, 2.2.1

I have a recursive function reading a "table of contents" of documents from a database. I would like to print numbering with the document that reflects where the item is in the tree, e.g. 1. First item, 1.1 Child of first item, 1.1.1 Child of child of first item, 1.2 Child of first item, 2. Second item, 2.1 Child of...

XSLT 1.0 recursion

I'm stuck with recursion, was wondering if anyone can help me out with it. I have <Receipts> and <Deposits> elements, that are not verbose, i.e. that a <Receipts> element doesn't have an attribute to show what <Deposit> it is towards. I need to figure out <Deposits> "still amount due" and when a last receipt towards it was paid if any. ...

merge sort recursion tree height

Hello! I am learning about recursion tree's and trying to figure out how the height of the tree is log b of n where n = 2 and one has 10 elements as input size. I am working with Merge sort. The number of times the split is done is the height of the tree as far as I understood, and the number of levels in the tree is height + 1. But ...

XSLT 1.0 help with recursion logic

Hello guys, I'm having troubles with the logic and would apprecite any help/tips. I have <Deposits> elements and <Receipts> elements. However there isn't any identification what receipt was paid toward what deposit. I am trying to update the <Deposits> elements with the following attributes: @DueAmont - the amount that is still due...

What is wrong with this recursive Windows CMD script? It won't do Ackermann properly

I'm trying to get to calculate the Ackermann function. A description of what I'm trying to achieve is at http://rosettacode.org/wiki/Ackermann_function. Using the test script, Test 0 4 gives me 5 which is correct. However Test 1 4 gives 5 not 6, and Test 2 4 gives 5 instead of 11. Where am I going wrong? ::echo off set depth=0 :ack i...

Two query in one with SQL Server

Hi, This is what I'm trying to do something similar to the following request, but I don't know if it's possible with the SQL-Server syntax: declare @idClient int select @idClient=idClient from table where entite is null and (SELECT * from table where entite=@idClient) is null Thanks. ...

Why does Gnumake from parent directory behave differently?

I am stumped as to why when I do a gnumake from the parent directory it behaves incorrectly, whereas, if I cd to the subdirectory and do gnumake it works correctly. In the parent makefile, I have a rule like this: .PHONY: zlib-1.2.5 zlib-1.2.5: @ echo Issuing $(MAKE) in $@ ... pushd zlib-1.2.5; make; popd I also tried it like...

Getting a "for each" loop in Java to run in different order everytime

Hi, Basically my problem is that I'm trying to write a method that finds a random path in a graph of strings, which takes as it's parameters a start string, an integer length and a Vector of strings that will store the path. I'm attempting to do this by first adding the starting string to our blank vector, recursing through its neighbor...

Recursion Problem in PHP

I need to create a valid xml from a given array(); My Method looks like this, protected function array2Xml($array) { $xml = ""; if(is_array($array)) { foreach($array as $key=>$value) { $xml .= "<$key>"; if(is_array($value)) { ...

How to detect the root recursive call?

Say we're writing a simple recursive function fib(n) that calculates the nth Fibonacci number. Now, we want the function to print that nth number. As the same function is being called repeatedly, there has to be a condition that allows only the root call to print. The question is: how to write this condition without passing any additiona...

java recursion on array

I have to create a program that finds all the possible ways of filling a square of size x by y. You place a block which takes up 2 spaces to completely fill. The problem is I don't know how to code it to the point where you can remember the placements of each square. I can get it to where it fills the board completely once and maybe tw...

Tail recursion in C++

Can someone show me a simple tail-recursive function in C++? Why is tail recursion better, if it even is? What other kinds of recursion are there besides tail recursion? ...

php run function on all images from one dir in recursive mode (noob)

hey guyz i have a function $result = create_watermark( 'input_file_name' ,'output_file_name'); i have dir called /images n have 500 images in it and all images are link images_(some_unknown_numbers).png (all png) now i want run them thru function in loop and want out put like /markedimage/images_1.png images_2.png images_3.pn...

Recursive powerof-function, see if you can solve it

First of all, this is not schoolwork - just my curiousity as I for some reason can't get my head around it and solve it. I come up with these stupid things all the time and it annoys the hell out of me when I cant solve them. Code example is in C# but solution doesn't have to be in any particular programming-language. long powerofnum(s...

If a jQuery function calls itself in its completion callback, is that a recursive danger to the stack?

Hi, I'm writing a little jQuery component that animates in response to button presses and also should go automatically as well. I was just wondering if this function recursive or not, I can't quite work it out. function animate_next_internal() { $('#sc_thumbnails').animate( { top: '-=106' }, 500, function() { an...

Find common nodes from two linked lists using recursion

I have to write a method that returns a linked list with all the nodes that are common to two linked lists using recursion, without loops. For example, first list is 2 -> 5 -> 7 -> 10 second list is 2 -> 4 -> 8 -> 10 the list that would be returned is 2 -> 10 I am getting nowhere with this.. What I have been think of was to check ...