recursion

Memory Allocation in Recursive C++ Calls

Hi, I'm having problems allocating and deallocating my memory in a recursive C++ program. So without using an automatic memory management solution, I wonder if anyone can help me resolve the memory leak I am experiencing. The following code essentially explains the problem (although it's a contrived example, please correct any mistakes...

How to best enforce single-level recursion in a SQL table?

Let's say you have a table for branches in your organization. Some of them are "main" branches, and others are satellite offices that roll up to a main branch. Other than this distinction, which only impacts a few things in the system, the branches are all peers and have the same attributes (address, etc.). One way to model this is in a ...

Is there any way to do n-level nested loops in Java?

In other words, can I do something like for() { for { for { } } } Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another? Of course, the idea is that there should be an "easy" or "the usua...

Prevent mutually recursive execution of triggers?

Suppose you have the tables Presentations and Events. When a presentation is saved and contains basic event information, such as location and date, an event will be created automatically using a trigger. (I'm afraid it's impossible for technical reasons to simply keep the data at one place and use a view.) In addition, when changing this...

PHP Arrays, appending depth of array item recursively to an array with the key of 'depth'

Per the example array at the very bottom, i want to be able to append the depth of each embedded array inside of the array. for example: array ( 53 => array ( 'title' => 'Home', 'path' => '', 'type' => '118', 'pid' => 52, 'hasChildren' => 0, ), Has a depth of one accordin...

What is the best way to handle recursion in smarty?

I found a couple of ways to handle recursion in Smarty, mostly based on including templates into themselves, which seems like ridiculous waste of resources. I found one solution, by Messju over at Smarty that seemed to be just right - but it is not supported and fails in the latest version of smarty :( For people asking: What I want sma...

Can you explain the concept of Recursion?

If you had to explain recursion to a novice how would you do it? ...

How to find all nodes in a subtree in a recursive SQL query?

I have a table which defines a child-parent relationship between nodes: CREATE TABLE node ( ' pseudo code alert id INTEGER PRIMARY KEY, parentID INTEGER, ' should be a valid id. ) If parentID always points to a valid existing node, then this will naturally define a tree structure. If the parentID...

Delphi folder scanner - Unicode folder names

Yo. I need to scan a directory and its sub-folders, I used FindFirst and FindNext procedures, but the TSearchRec's Name property is a string, thus unicode folder names (hebrew, arabic etc) are '?????' in the Name property. I tried using TntComponent, with WideFindFirst, WideFindNext and TSearchRecW. But I still get ?????? for folder na...

Recursion for user input - elegant or strange?

Dev-cpp comes with an example program Jackpot, which has a GetResults function in it: void GetResults () { . . . else if (i>j) { cout << "Too BIG\n"; life = life - 1; // -1 to the user's "life" cout << "Number of remaining life: " << life << "\n\n"; GetResults(); } Is this an...

iterative version of easy recursive algorithm

I have a quite simple question, I think. I've got this problem, which can be solved very easily with a recursive function, but which I wasn't able to solve iteratively. Suppose you have any boolean matrix, like: M: 111011111110 110111111100 001111111101 100111111101 110011111001 111111110011 111111100111 111110001111 I know this is ...

A recursive way to display Exception Messages in ASP.NET

Hello, I have started to make heavy use of exceptions, I'm sure I'll grow out of it as a learn the advantages and disadvantages the hard way, but until I've become an exception guru I'd like to know if this technique is acceptable. I intend to wrap, say a database exception in my own 'SorryFailedToSaveYourData' exception and then recur...

passing pointer to recursive function in C

I'm just starting on the road the learning C, and ran into some difficulty: The code listed below is giving me the following error: Attaching to program: `/workfolder/cocoa/c_stuff/bookshelf/build/Debug/bookshelf', process 1674. Cannot access memory at address 0xa0df194 Cannot access memory at address 0xa0df194 // code start #define ...

New to Java - Converting to Binary, Counting 1's, Recursive

Hey Everyone I just started Data Structures and Algorithms which is taught in Java. So far I've only learned C++ in my life so I'm still VERY new to using java. Anyways I have a homework problem I'm a little stuck on: Write a recursive method that returns the number of 1's in the binary representation of N. Use the fact that this is e...

Recursion or iteration?

I love recursion. I think it simplifies things a lot. Another may disagree; I think it also makes the code a lot easier to read. However, I've noticed that recursion is not used as much in languages such C# as they are in LISP (which by the way is my favorite language because of the recursion). Does anybody know if there is any good re...

Injecting advice to a recursive method in Spring.Net?

I'm trying to use Spring.NET's support for AOP to do dependency injection/inversion of control/aspect-oriented programming (sorry for the slew of buzzwords - maybe I'll post a separate question asking someone to clarify the difference :) ). Specifically, I want to have intercept a recursive method call, so that every time that the meth...

Should I use recursion or memoization for an algorithm?

If I have a choice to use recursion or memoization to solve a problem which should I use? In other words if they are both viable solutions in that they give the correct output and can be reasonably expressed in the code I'm using, when would I use one over the other? ...

Can a lambda function call itself recursively in Python?

A regular function can contain a call to itself in its definition, no problem. I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no name to refer back to. Is there a way to do it? How? ...

Recursive SQL for a menu system.

I have a table for a menu system with the following structure, and some data. ID, Text, ParentID, DestinationID 1, Applications, (null), (null) 2, Games, (null), (null) 3, Office, 1, (null) 4, Text Editing, 1, (null) 5, Media, (null), (null) 6, Word, 3, 1 7, Excel, 3, 2 8, Crysis, 2, 3 What I need is a query to which I can pass the m...

recursively concatenating a javascript functions arguments

I came across a javascript puzzle asking: Write a one-line piece of JavaScript code that concatenates all strings passed into a function: function concatenate(/*any number of strings*/) { var string = /*your one line here*/ return string; } @ meebo Seeing that the function arguments are represented as an index...