I have a large result set assembled in a parent/child relationship. I need to walk the tree and display the results to the user.
I've done this before using recursion, but because my result set may be large, I want to avoid the possibility of receiving a StackOverflowException.
I found the following example on MSDN which uses a Stac...
We have the following example table (actually taken from another example here on stackoverflow...)
CREATE TABLE example (
id integer primary key,
name char(200),
parentid integer,
value integer);
And given a specific child we want to get the top Parent.
I know of the tablefunc connectby function but that is for getting a pa...
Hi,
I have a set of objects in a hierachy. There's a top "root" node and that has child nodes, which in turn have child nodes etc. I'm trying to save this structure into a DB using the nested set model, where each "side" of each node is numbered to define the hierarchy, as in:
http://dev.mysql.com/tech-resources/articles/hierarchical...
Has anyone written or thought about writing an iterator for a composite (tree) structure without using recursion?
If so can you share your ideas? Thks
Edit: I was thinking of Java for lang.
...
Pointless Dribble
Okay This is another weird one from me, i want to thank OIS for helping me out on my last question... which deals with this same kind of funky array manipulation... i studied that code in depth and i feel it has helped me become better with recursive array manipulative functions. However, once again i find my self in ...
How is a JUMP and CALL instruction different? How does it relate to the higher level concepts such as a GOTO or a procedure call? (Am I correct in the comparison?)
This is what I think:
JUMP or GOTO is a transfer of the control to another location and the control does not automatically return to the point from where it is called.
On...
I have some(say 9, no not definite) unique strings from database(A,B,C,D,E,F,G,H) and I want to create unique combination of these fields to populate the listbox so that user can select single or different combination of these string fields
like
A,B,C,D,E,F,G,H,
AB,AC,AD,AE,AF,AG,AH,AC,AD,AE,AF,AG,AG,AH,...
ABC,ABD,ABE,ABF,ABG,ABH,ACD,A...
In my Python application, I need to write a regular expression that matches a C++ for or while loop that has been terminated with a semi-colon (;). For example, it should match this:
for (int i = 0; i < 10; i++);
... but not this:
for (int i = 0; i < 10; i++)
This looks trivial at first glance, until you realise that the text betwe...
projectEuler3(600851475143);
var projectEuler3 = function (composite) {
var result = 2;
while(composite > 1)
{
if (composite % result)
{
result++
} else {
composite = composite / result;
console.log(result);
}
}
};
...
As far as I know, most recursive functions can be rewritten using loops. Some maybe harder than others, but most of them can be rewritten. So the question is, under which conditions does it become impossible to rewrite a recursive function using a loop (if such conditions exist)?
Clarification: I know how to convert a recursive functi...
How can I recursively delete all files & directories that match a certain pattern? e.g. remove all the ".svn" directories and the files they contain?
(Sadly DOS only)
...
I've got a 'Task' table with the following columns (the TaskOrder is for ordering the children within the scope of the parent, not the entire table):
TaskId
ParentTaskId
TaskName
TaskOrder
I've got this CTE query to return all the rows:
with tasks (TaskId, ParentTaskId, [Name]) as
(
select parentTasks.TaskId,
parentTa...
Suppose you write a function in SQL Server that conditionally calls itself. If you are writing the function from scratch, finish it, and try to create it, SQL Server complains.
The complaint is that the function you call from your function doesn't exist. Of course it doesn't, it's recursive!
To actually make it work, you have to comm...
Hi,
First of all, I swear this is not homework, it's a question I was asked in an interview. I think I made a mess of it (though I did realise the solution requires recursion). Here is the question:
Implement the count() method which returns the number of nodes in a tree. If a node doesn't have either a left or right child, the relevan...
I am attempting to write a 'User Control' in WinForms .NET (not ASP.NET). The control is relatively simple. It will contain a label, a button, and a DataGridView.
However, the control needs to be able to instantiate itself, i.e. when the user clicks the button (of the parent control) at least 1 nested (children) control of the same ty...
I´m trying to break a number into an array of numbers (in php) in the way that for example:
25 becomes (16, 8, 1)
8 becomes (8)
11 becomes (8, 2, 1)
I don´t know what the correct term is, but I think the idea is clear.
My solution with a loop is pretty straightforward:
$number = rand(0, 128);
$number_array_loop = array();...
Supposing I have a File f that represents a directory, then f.delete() will only delete the directory if it is empty. I've found a couple of examples online that use File.listFiles() or File.list() to get all the files in the directory and then recursively traverses the directory structure and delete all the files. However, since it's ...
Image you are creating a DB schema for a threaded discussion board. Is there an efficient way to select a properly sorted list for a given thread? The code I have written works but does not sort the way I would like it too.
Let's say you have this data:
ID | ParentID
-----------------
1 | null
2 | 1
3 | 2
4 | 1...
Look at this simple function
def prime_factors(n):
for i in range(2,n):
if n % i == 0:
return i, prime_factors(n / i)
return n
Here's the result of prime_factors(120)
(2, (2, (2, (3, 5))))
Instead of nested tuples, I want it to return one flat tuple or list.
(2, 2, 2, 3, 5)
Is there a simple way to do that?...
I have a CTE that's doing some recursion. The easiest way to imagine the problem space is a resistor that is used in cars all over the world and you have all that information. Resistor A is used in Board B and C which is used in DashAssembly D,E,F...ZZ which is used in Car AAA, AAB and AAC.
I got the CTE working with one part, checked ...