recursion

access 2003 parent/child recursive search

How do i create a parent/child relationship that VB6.5 will put into a tree like view using a recursive search. I have a simple table structure that I'm experementing with before I begin using the main database. ID | Part | ParentId -----+-----------+--------- 1 | Tire | 0 2 | Door | 0 3 | Break | 1 4 ...

C++ Function Calling Itself

Question I wish to know if this is a viable way to implement variable depth recursion so that I can run a function at each step and any better/other solutions to the description problem. Description Suppose I wish to have a function that fills an array either in pattern x,y,x,y,x,ywhere x and y are variables defined by some algorithm and...

Recursion inside while loop, How does it work ?

Can you please tell me how does this java code work? : public class Main { public static void main (String[] args) { Strangemethod(5); } public static void Strangemethod(int len) { while(len > 1){ System.out.println(len-1); Strangemethod(len - 1); } } } I tried to debug it ...

Ocaml continuation passing style

I'm new to ocaml and tryin to write a continuation passing style function but quite confused what value i need to pass into additional argument on k for example, I can write a recursive function that returns true if all elements of the list is even, otherwise false. so its like let rec even list = .... on CPS, i know i need to ad...

Getting all possible combinations of N items in X Groups.

I have a list of Groups that can vary in number, with Items in these groups that also vary in number. I've been racking my head over a way to get all possible combinations of 1 Item from every Group. Bonus: I also need all combinations of not having every items from a group. I've seen and done what was mentioned before, but that requ...

What is a practical difference between a loop and recursion

I am currently working in PHP, so this example will be in PHP, but the question applies to multiple languages. I am working on this project with a fiend of mine, and as always we were held up by a big problem. Now we both went home, couldn't solve the problem. That night we both found the solution, only I used a loop to tackle the probl...

[bash] don't know howto deal with dir/file with spacing as glob in bash scripting

Since i have some video courses in my laptop. I now want to calculate the total time of every course. So i write a simple script with bash. It succeeds for file/dir without space. But for dir/files with space, it goes wrong. I have tried to set IFS to something else, it doesn't work either. Well, there also some bugs in it. #!/bin/ba...

Python: Elegant way to replace a given dictionary by child key somewhere in a tree?

Is there some kind of enumeration library or method I should use or should I write from scratch with recursion? I'm parsing a JSON tree into an object tree as it happens, and I'd like to replace some nodes with other kinds of objects. E.g: db = {'bigBang' : {'stars': {'planets': {}, 'is_list':true ...

PHP: Iterating through array?

Hi, What I want, is a function that searches through my array, and returns all the children to a specific node. What is the most appropriate way to do this? Will recursion be necessary in this case? I have previously constructed a few quite complex functions that iterates with or without the help of recursion through multi-dimensiona...

Summing values of recursive functions in XSLT

I have XML like this: <assessment name="Assessment"> <section name="Section1"> <item name="Item1-1"/> <item name="Item1-2"/> <item name="Item1-3"/> <item name="Item1-4"/> <item name="Item1-5"/> </section> <section name="Section2"> <item name="Item2-1"/> <item name="Item2-2"/> <item name="Item2-3"/> <sec...

Help modifying recursive function

Given a canvas, let's say 10x10, and given 3 rectangles/squares. Canvas = 10x10 Rectangle 1 = 2x2 Rectangle 2 = 3x3 Rectangle 3 = 2x4 I've created a recursive function that loops every position of every rectangle on the canvas, and it works fine. (I've included the function below incase anyone wants to see it but I don't think it's n...

Building a recursive delete function (in php)

Hi, Here's the deal. I've got a "tree" or a "subtree" that I want to navigate and delete every element in. Each "node" may contain links to other nodes below it (no problem) OR may contain links OUTSIDE that particular "tree"/"subtree". How can I build a function that only deletes "within" the specified tree? ...

Recursive calls to database in perl

I know there's an easy way of doing this, but my recursion abilities are out of practice. Given a database table that has three fields: id label child_id I should be able to put together a recursive function that will give output like this: child (input of program) parent1 parent2 grandparent1 great-grandparent1 gr...

Find the longest path between any two nodes.

I have a binary tree. I need to write Java recursive method that will give longest path between two nodes. For example longest path if following tree is 7 (7-8-5-13-15-18-16-17). http://img294.imageshack.us/img294/130/treeb.jpg What's the way to resolve this problem? (The method: public static int longestPath(Node n) ) ...

recursive method - not all code paths return a value!

it says not all code paths return a value private string Fisrt(string nonTerminal) { for (int j = 0; j < 6; j++) { if (Tokens[j, 0] == nonTerminal) { if (char.IsLower((char)Tokens[j, 3][0])) return (Tokens[j, 3]); else Fis...

Binary Tree: Longest path between 2 Nodes

Calculate the longest path between two nodes. The path is in an arch. Signature of method is: public static int longestPath(Node n) In the example binary tree below, it is 4 (going thru 2-3-13-5-2). This is what I have right now and for the given tree it just returns 0. public static int longestPath(Node n) { if (n != null) {...

When to Return a Recursive Function?

I have a question on return and recursive functions. This is again based off of a binary Tree which I am currently working on. The code is void Tree::display() { if( !root_ ) return; display_r(root_); } void Tree::display_r(Tree *node) { if( 0 == node ) return; display_r(node->left_); std::cout <<...

Generate a nested list from flatten data in Python

Hi, To generate a Table of Content, I have these data available in a Python list: data = [ {title: 'Section 1', level: 1, page_number: 1}, {title: 'Section 1.1', level: 2, page_number: 2}, {title: 'Section 1.2', level: 2, page_number: 3}, {title: 'Section 2', level: 1, page_number: 4}, {title: 'Section 2.1', level: ...

Is a recursively called stored procedure possible in SQL Server?

Here is what I have as VBScript Subroutine: sub buildChildAdminStringHierarchical(byval pAdminID, byref adminString) set rsx = conn.execute ("select admin_id from administrator_owners where admin_id not in (" & adminString & ") and owner_id = " & pAdminID) do while not rsx.eof adminString = adminString & "," & rsx(0) ...

SQLite and hierarchy in one request, how to do so?

Facts I have a pretty simple table: ID, name, PARENT_ID I would like to retrieve the hierarchy from down to top in one query using SQLite. Question : How can I do that ? Is there any request that will let me do that in One request? I´ve read about the 'Modified Preorder Tree Traversal', it is straight forward to get the hierarchy ...