recursion

WITH Common Table Expression vs. CREATE VIEW performance

I have several queries which use a WITH clause, or Common Table Expression, with a UNION ALL statement to recur through a table with a tree like structure in SQL server as described here. Would I see a difference in performance if I were to CREATE that same VIEW instead of including it with the WITH clause and having it generated every ...

how to loop over looped elements?

I'm creating a tree-structure of categories with parentid's which can be called from children in such a way: ID | Name | ParentID 1 1 0 2 2 1 3 3 2 4 4 1 Resulting in this: 1 = 1 2 = 1 -> 2 3 = 1 -> 2 -> 3 4 = 1 -> 4 which means 3 is a child of 2, which is a child of 1. when trying to get this idea ...

python ctype recursive structures

I've developped a DLL for a driver in C. I wrote a test program in C++ and the DLL works fine. Now I'd like to interract with this DLL using Python. I've successfully hidden most of the user defined C structures but there is one point where I have to use C structures. I'm rather new to python so I may get things wrong. My approach is t...

Excel VBA - Create Treeview from recordset

Hi Guys and Girls, I have a SQL 05 Stored Procedure that brings back around 180 rows with the structure: ID | Name | ParentId. What I would like to do is create a Treeview based on the records returned. Below is a sample I adapted from elsewhere on the forum (here) I nearly have it doing what I want but not quite. This is the proble...

Tree structure with subclassed nodes, how to apply operation on a subset of children

I have a tree structure A -> B -> D -> Y -> C -> X -> X I want to do an operation on all objects of class X, or all the children objects of class D (for example). I want to call start this operation from any node in the tree (ie recursively). For e.g, A.SetupDecorators(); (although I'm open to suggestions) All classes i...

What is tail-recursion elimination?

Steve Yegge mentioned it in a blog post and I have no idea what it means, could someone fill me in? Is it the same thing as tail call optimization? ...

recursive gmake question

Hello, I need to write a quick makefile for building all my projects. This is C++ code and I am using gmake. Say I have a list of directories, I want to cd to each, issue gmake command and if it succeeds, go to the next one and so on. I cooked this by looking at the gmake manual .PHONY: all clean dirs $(DIRS) dirs: $(DIRS) $(DIRS):...

Recursive? looping to n levels in Python

Working in python I want to extract a dataset with the following structure: Each item has a unique ID and the unique ID of its parent. Each parent can have one or more children, each of which can have one or more children of its own, to n levels i.e. the data has an upturned tree-like structure. While it has the potential to go on for i...

Understanding Recursion in Java

I'm having a tough time in understanding the following code based on recursion algorithm in Java. I don't understand, what's the different value x and y have when they call within one another? I tried to get the right value by calling System.out.print() within a code, but still get no help. public class RecursionExample { private ...

How to avoid infinite recursion in C++ class templates

I have a matrix class with the size determined by template parameters. template <unsigned cRows, unsigned cCols> class Matrix { ... }; My program uses matrices of a few sizes, typically 2x2, 3x3, and 4x4. By setting the matrix size with template parameters rather than run-time parameters allows the compiler to do a lot of inlinin...

Explicit type recursion in F#

Inspired by this question: Is explicit type recursion possible in F#? type 'a Mu = In of 'a Mu 'a let unIn (In x) = x This code unfortunatly gives "Type parameter cannot be used as type constructor. Remarks: This construct is used in the paper Functional Programming with Overloading and Higher-Order Polymorphism, for example. Exam...

Ordering on a field in the 'through' Model of recursive ManyToMany relation in Django.

Assuming the following model: class Category(models.Model): related = models.ManyToManyField('self', symmetrical = False, through = 'CategoryRelation', null = True, blank = True) Assuming the following intermediate 'through' relation: class CategoryRelation(models.Model): source = models.ForeignKey('Category', null = False, b...

Rails Recursive Multi Model Form Problem

I have a recursive relationship between models: Test --> Questions -------> (has_one) Remediation ------------> (has_many) Remediation_Questions -----------------> (has_one) Question Basically the idea is each question has a remediation (some link or block of text) associated with it. Each Remediation then has a set of remediation que...

Recursive list with vbscript

I have a csv file with userid and manager fields. How can I list all userids that report to a specific manager and its direct reports, drilled down to the last user. Need a quick vbscript. Thanks. ...

How do I save the original argument in a recursive function in PHP?

Hi, I'm in PHP working on an Euler problem. I have this function so far: <?php $biggest = 0; $counter = 1; function test($i){ global $biggest; global $counter; if ($i == 1) { echo "I'm done! Took me $biggest steps"; } else { if ($i%2 == 0) { $counter = $counter + 1; if ($counter>$biggest) { ...

Using recursion to add odd numbers

Hi Friends, I am trying to write a method to calculate the sum of the odd numbers in all the numbers less than the given number. so eg. CalcOdd(7) would return 5 + 3 + 1 = 9. CalcOdd (10) would return 9 + 7 + 5 + 3 + 1 = 25 etc The method needs to take in a number, subtract 1, then recursively work backwards adding all odd numbers unti...

Recursive generation + filtering. Better non-recursive ?

I have the following need (in python): generate all possible tuples of length 12 (could be more) containing either 0, 1 or 2 (basically, a ternary number with 12 digits) filter these tuples according to specific criteria, culling those not good, and keeping the ones I need. As I had to deal with small lengths until now, the function...

What's the correct way to recurse with lists in Java?

When recursing with Lists in Java, I frequently end up allocating and copying lists many many times. For example, I want to generate a List<List<Integer>> of all possible Integer sequences where: Every number is between 1 and 9 Every number is greater or equal to the number before it A number can appear between 0 and 3 times in a row. ...

python scooping and recursion

I am struck in a small recursive code. I have printed output and it prints fine but when I try to put a counter to actually count my answers, it gives me scooping errors. total = 0 def foo(me, t): if t<0: return if t==0: total = total+1 return for i in range(1, me+1): total = total+1 return foo(i, t-...

xcode debugging maximum depth for investigating variables?

Hey There! I use Xcode to code for a current iPhone Project. It's the first time i work with XCode. What i wonder is, whether i need to set somewhere how 'deep' i can be able to recursively look into the variables in the debugger. If i have the debugger open, i can see all the current variables and open them. I can see all the fields o...