recursion

SQL recursive query

Possible Duplicate: Recursive function in sql server 2005? How do you perform an iterative query on a table? I have a simple table which consists of a: KeyField, childID, parentID Starting with a childID, I want to pull the parentID and then query again to see if that parent (which is now the child) has its own parent, worki...

Backtracking recursion question

There is a bag that can take X kilogram. You will get an array of stuff and their weight. Print true and the each weight of the stuff and false if there is no answer Example: for X=20 array {4,9,1,15,7,12,3} print true and 4 1 15 (4+1+15=20) ...

Scheme max on sub lists

I've written a function to get the maximum value from a list of nested lists, I have the general form of the function down right; it works on flat lists and nested lists but seems to fail when there are sibling nested lists. Here is my code: (define (multi-max array) (cond ((null? array) 0) ((number? (car array)) (if (>...

extra space for recursive depth-first search to store paths

I am using depth-first search to identify paths in a directed weighted graph, while revisiting nodes that belong to a cycle, and setting cutoff conditions based on total distance traveled, or stops from the source node. As I understand, with recursion an explicit stack structure is not required for depth first search, so I was wonderin...

How to keep count in a recursive function? [python]

Hi, I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count != 0 to begin with....

Different results from yield vs return

I don't really understand how yield statement works in this situation. The problem says that given an expression without parentheses, write a function to generate all possible fully parenthesized (FP) expressions. Say, the input is '1+2+3+4' which should be generated to 5 FP expressions: (1+(2+(3+4))) (1+((2+3)+4)) ((1+2)+(3+4)) ((1+(2...

How can I build an infinitely recursive listview control?

Not sure I'm asking the right question, but it's a start. I have a user control with a ListView and, ideally, I would like to nest this same control inside of the ListView to provide recursion. This would behave somewhat like a TreeView with child nodes. This might be a monumentally bad idea. :) In fact, I feed like MSFT is pointing me...

PHP: How do I search an array for all entries of a specific key and return value?

I've got a multidimentional array such as: $array = array( array('test'=>23, 'one'=>'etc' , 'blah'=>'blah'), array('test'=>123, 'one'=>'etc' , 'blah'=>'blah'), array('test'=>33, 'one'=>'etc' , 'blah'=>'blah'), ); How to I search the array for all the keys 'test' and get the value? I wish to add all of the values of 'test' found ...

PHP: get current array key?

$array = ( array('1231415'=>array('foo'=>'bar', 'test'=> 1)), array('32434'=>array('foo'=>'bar', 'test'=> '0')), array('123244'=>array('foo'=>'bar', 'test'=> 0)), array('193928'=>array('foo'=>'bar', 'test'=> 1)) ); I have an array that has (many) random keys, the ID number. I need to test each array within if 'test' = ...

Can this be called recursive?

function move() { pos = pos+1; t = setTimeout(move, 100); } Can that be called recursive? If yes, could you provide any reference? Thanks in advance ...

Recursively list files in Java

How do I recursively list all files under a directory in Java? Does the framework provide any utility? I saw a lot of hacky implementations. But none from the framework or nio ...

Recursive regular expression,how to match the coupled string with regular expression?

... AA BB sysodufsoufdds BB AA ... Where AA,BB can be arbitary consecutive string with no space in it. But I want to get the outest pair:AA More examples: Input: a HH CC abc CC HH c Output: HH Input: x YYYY j DD GG DD hsu DD GG DD k YYYY o Output: YYYY To make my question more general,how to match a speci...

shouldn't PHP array recursion throw an error?

This is the test and the response I get. I think this could be problematic and should throw an error or a notice but I cannot understand why is tolerated. <?php $test = array( 0 => 'test', 1=> &$test ); var_dump( $test ); // array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> s...

C# - Entity Framework - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll Make sure you do not have an infinite loop or infinite recursion. The below code is called on a success of this method: internal static List<RivWorks.Model.Negotiation.ProductsSold> GetProductsSoldByCompany(Guid CompanyID) { var ret = from...

How can I order by the result of a recursive SQL query

I have the following method I need to ORDER BY: def has_attachments? attachments.size > 0 || (!parent.nil? && parent.has_attachments?) end I have gotten this far: ORDER BY CASE WHEN attachments.size > 0 THEN 1 ELSE (CASE WHEN parent_id IS NULL THEN 0 ELSE (CASE message.parent ...what goes here ) ...

Concatenate JOINS or write recursive function - problem with dynamic number of JOIN queries

I have the following problem to solve: Let's say there is a table A that contains an number of elements, this table is copied to become table B. In table B some of the original elements are lost and some are added. A reference table AB keeps track of these changes. Then table B is copied to be table C and again some of the existing elem...

How to write a simple preorder DOM tree traversal algorithm in jQuery?

I'd like to take the code found here: http://www.jslab.dk/articles/non.recursive.preorder.traversal.part2 // HTML element var root = document.documentElement; recursivePreorder(root); // Recusively find and handle all text nodes function recursivePreorder(node) { // If node is a text node if (node.type == 3) { // Do somethin...

Opening and Printing files using Recursion in python

So I am trying to write a code that opens a file and inside that file might be empty or contains the name of other files to open on each line. For example. 1.txt has 2.txt. on the first line and 3.txt on the second line. 2.txt is a empty file and 3.txt has 4.txt on the first line. I have to have an output that prints the files that the c...

Visualisation of Tree Hierachy in HTML

I am looking of inspiration for doing interaction design on a hierachy/tree structure. (products with a number of subproducts, rules that apply for selecting subproducts). I want to have a tree where there is a visible connection between sub-nodes and their parent node. And i also want to visualize which rules that apply for selecting t...

How did you practically use recursion?

How did you practically use recursion? I mean practical problems you had to solve in day to day programming, be that for work or for pleasure. Not school tasks/homeworks but something you did for yourself or others. The ones where I used it myself are: drawing some fractals traversing directory tree to search for a file traversing the ...