Hi again.... I'm either really stupid or my program hates me. Probably both.
Problem: I am searching through a tree to find a value that is passed. Unfortunately, it does not work. I started debugging it with prints and stuff, and what is weird is it actually finds the value... But skips the return statement!!!
/**
* Returns...
I have a question about the merits of two different approaches to implementing a recursive method. I've always followed the approach of version 1, i.e., accepting a single Node parameter, but I recently encountered the style used in version 2, which accepts a collection of Nodes.
Consider the following Node class, along with the 2 ve...
function createPath($id, $category_tbl, $path) {
$s = "SELECT * FROM ".$category_tbl." WHERE ID = $id";
$r = mysql_query($s);
$row = mysql_fetch_array($r);
if($row['PARENT_ID'] == 0) {
$path .=$row['TITLE'].'-';
}
else {
$path .='-'.$row['TITLE'];
createPath($row['PARENT_ID'],$category_tb...
I have the following code, any ideas on how to resolve this issue, instead of declaring a int variable outside the function? I get the following compiler error: Use of unassigned local variable 'counter'
public static int GetNumberOfDevicesForManagementGroup(Guid managementGroupId, bool firstTime)
{
int counter;
using (var c...
Hi,
I have a tree structure in the DB with TreeNodes table. the table has nodeId, parentId and parameterId. in the EF, The structure is like TreeNode.Children where each child is a TreeNode...
I also have a Tree table with contain id,name and rootNodeId.
At the end of the day I would like to load the tree into a TreeView but I can't fi...
I've heard that running recursive code on a server can impact performance. How true is this statement, and should recursive method be used as a last resort?
...
If we consider recursive function in C/C++, are they useful in any way? Where exactly they are used mostly?
Are there any advantages in terms of memory by using recursive functions?
Edit: is the recursion better or using a while loop?
...
Greetings:
I have the metaphor of Parent Transactions in my JSP web application. I have transaction ID's stored in a database and the requirement is to display all of the children of the parent and then the subsequent children of the parent's children. In reality this list of parents and their children will never be more than 4 or 5 lev...
Full disclosure, this is part of a homework assignment (though a small snippet, the project itself is a game playing AI).
I have this function built into a tree node class:
def recursive_score_calc(self):
current_score = self.board
for c in self.children:
child_score = c.recursive_score_calc()
...
$startDate = 20130201;
$date = 20130505;
$aDates = $this->getDates($startDate, $date);
public function getDates($startDate, $date) {
$tmpStartDate = date("Ymd", strtotime($startDate.'+1 Day'));
$tmpEndDate = date("Ymd", strtotime($tmpStartDate.'+1 Month'));
if($date >= $tmpStartDate && $date <= $tmpEndDate) {
...
I've been writing more Lisp code recently. In particular, recursive functions that take some data, and build a resulting data structure. Sometimes it seems I need to pass two or three pieces of information to the next invocation of the function, in addition to the user supplied data. Lets call these accumulators.
What is the best way to...
I'm trying to implement an iterative version of Tarjan's strongly connected components (SCCs), reproduced here for your convenience (source: http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm).
Input: Graph G = (V, E)
index = 0 // DFS node number counter
S = empty ...
I have a menu being built via a multi-dimensional array. A current item is set by matching its url attribute with the current request. I want this value to bubble up to its parents, but I can't for the life of me get it working - I'm sure I've been close, but it's proving a bit tricky. Here's the array:
Array
(
[children] => Array
...
Hi all. I am building a template parser.
The template parser works like this:
Tokenize (make for each part of the template code a token)
Parse
Use my ParserHelper class. You can add rules for this system, and then it checks the token list for a valid grammar.
Add / change some tokens for extra functionality
Compile (translate to php ...
int findLargest (ListNode *p)
// --------------------------------------------------------------------------
// Preconditions: list head pointer is passed as a parameter.
// Postconditions: returns the largest value in the linked list.
// --------------------------------------------------------------------------
{
if (p->item != NULL...
Hello,
I'm a programming student in my first C++ class, and recently we were given an assignment to implement a recursive program that finds the first occurrence of a given substring in a given string.
For example:
int StringIndex("Mississippi", "sip"); // this would return 6
The hint we are given is to use a recursive helper functi...
I'm a programming student in my first C++ class, and recently we were encouraged to write a simple recursive function to find the first occurrence of a substring in a given string. If found, it returns the index. If the substring is not found, the index_of() function should return -1. We are encouraged to use a helper function that ta...
Similar to this: http://stackoverflow.com/questions/426878/is-there-any-way-to-do-n-level-nested-loops-in-java
I want to create a recursive function, which generates N nested loops, where the indicies depend on the depth of the loop. So basically, I want to do this recursively:
// N = 3, so we want three nested loops
for(int i1 = 0; i...
I need to work on a system that uses automake tools and makes recursively.
'make -n' only traces the top level of make.
Is there a way to cause make to execute a make -n whenever he encounters a make command?
...
I have a function specification that states it that should evaluate a polynomial function of one variable. The coefficient of the function is given as a list. It also accepts the value of the variable as a real.
For example: eval(2, [4, 3, 2, 1]) = 26 (1*x^3 + 2*x^2 + 3*x^1 + 4*x^0, where x = 2)
Here's the function in python, but I'...