recursion

Are all scheduling problems NP-Hard?

I know there are some scheduling problems out there that are NP-hard/NP-complete ... however, none of them are stated in such a way to show this situation is also NP. If you have a set of tasks constrained to a startAfter, startBy, and duration all trying to use a single resource ... can you resolve a schedule or identify that it cannot...

PHP: Warning: array_merge_recursive(): recursion detected

I have a list of arrays (unknown amount), I need to merge all of them recursively. So what I did what create an array of all of those arrays and pass them into this function: function mergeMonth($array) { foreach($array as $date_string => $inner_array) { if(isset($temp_inner_array)) { $temp_inner_arr...

Wrapping my head around N parent->child associations

I'll try to explain this the best I can. I'm having quite a bit of difficulty trying to figure out this logic. Basically, I have a collection that includes thousands of objects which are each made up of a Parent and a Child property. So, roughly, this: public class MyObject{ public string Parent { get; set; } public string ...

Are recursive functions re-entrant

I have seen many recursive functions(mostly used in computing some mathematical operations e.g. factorial, sum of the digits in a number, etc...) which involve use of a static variable which holds the result of the each recursive call/operation, and uses it for the subsequent calls. So does that make recursive functions non-rentrant and...

Returning binomal as a tuple

I want to save the results of my function binomal_aux to a tuple but I don't have an idea how to, here is my code I have right now. def binomal (n): i=0 for i in range(n): binomal_aux(n,i) #want this to be in a tuple so, binomal (2) = (1,2,1) return def binomal_aux (n,k): if (k==0): return 1 elif...

database tree to multidimensional array

Hi, i have a simple database tree with parentid and i want to read the db and get an array like above Array ( Title: Category 1 Children => Array ( => Title: Category 1.1 => Title: Category 1.2 Children => Array ( ...

Instead of making an if() for each control type, is there a cast that will allow me to dynamically set the type of control?

I'm iterating through my controls on this web page and when a button is pressed to modify a piece of a data, I'm disabling the other controls on the page. Such controls consist of TextBoxes, ListBoxes, and Buttons. All of these controls have the Enable property so I was wondering if there was a way to just cast the control to some kind o...

Why won't this Prolog predicate unify?

Hi, I'm writing a predicate to find all possible successor states for an iteration of A* and put them in a list like [(cost, state), ...] , which stands at this at the moment: addSuccessors(L, [], _). addSuccessors(L, [X|T], OrigList) :- memb(OrigList, Index, X), add((X, Index), L, List2), ...

Stop condition for printing linked structs?

I have the following struct: struct cell { int nmbr; struct cell *p; }; I have created a chain of linked structs from this type. Every struct is connected to its predecessor through *p. If I decide to print all nmbrs with a recursive algorithm as shown below, how do I define the stop condition? void write(struct cell* l) { ...

Why should recursion be preferred over iteration ?

Iteration is more performant than recursion, right? Then why do some people opine that recursion is better (more elegant, in their words) than iteration? I really don't see why some languages like Haskell do not allow iteration and encourage recursion? Isn't that absurd to encourage something that has bad performance (and that too when m...

Jquery issue with passing function click to function

I would like to push data from mysql db to div every x seconds. at window.setTimeout(update, 60000); - how to pass in the btnStart.click function into it again??? Not too sure about the syntax for passing in function call. Here's the code for reference $('#btnStart').click(function() { $.ajax({ url: "ajax.php", type: "POST...

Regex: recursive backreferences - what for?

I found some interesting possibility in many regex engines: It's possible to place backreference inside the capture group and reference this group. For example: (\1) My question: for what regex patterns it may be used? I can't imagine... ...

Creating polymorphic recursive types in Haskell

Hi I'm trying to create a Tree type in Haskell. I've used this simple data constructor for storing a tree in which each node can either be empty, be a leaf containing an integer, or be a node containing an integer with branches to two other leaves/nodes. Here's what I've got: module Tree ( Tree(Empty, Leaf, Node) ) where data Tree = E...

Getting hierarchy data from a self-referencing table

Let's say you have the following table: items(item_id, item_parent) ... and it is a self-referencing table as item_parent refers to item_id. What SQL query would you use to SELECT all items in the table along with their depth where the depth of an item is the sum of all parents and grand parents of that item. If the following is the co...

Recursive descent parser for algebraic expressions in java

This is the grammar: Expression= expression+term|expression-term|term term=term*factor|term/factor|factor factor=id|expression I am trying to implement a recursive descent parser. This is the algorithm I came up with ** class main create expression object take input from user and send it to the expression class ** Class Expres...

Merge sort from "Programming Scala" causes stack overflow

A direct cut and paste of the following algorithm: def msort[T](less: (T, T) => Boolean) (xs: List[T]): List[T] = { def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match { case (Nil, _) => ys case (_, Nil) => xs case (x :: xs1, y :: ys1) => if (less(x, y)) x :: merge(xs1, ys) e...

Oracle - Recursive query is not recursing (not as much as I'd like)

I had an idea that I could write a query to find all the decendent tables of a root table, based on foreign keys. Query looks like this: select level, lpad(' ', 2 * (level - 1)) || uc.table_name as "TABLE", uc.constraint_name, uc.r_constraint_name from all_constraints uc where uc.constraint_type in ('R', 'P') start with uc.table_name ...

Count lines in files in folders recursively

In C#, what is the best way to get a count of the total number of lines in all the files in a directory and all of its subdirectories? The obvious answer is to make a recursive function to go through all of the directories and use the strategy from this question to count the lines in each file. Is there a better/easier way? ...

jQuery recursive iteration over objects

The other day I thought I saw an object iterator in jQuery that had a flag that could be set to recursively iterate over child objects. I thought it was part of jQuery.each(), but now I don't see that capability in the docs. Is there any such iterator in jQuery that can be automatically recursive? (I know how to do it in javascript. J...

List parameters in recursive calls (C)

I'm designing a recursive algorithm : int f(int[] a, int[] b){ ----changing a here ----changing b here f(a,b) ----writing a here ----writing b here } I know all arrays are pointers so this code should be problematic. It'll write the final values of a and b after all the recursive calls finished. I dont want that to happen. What shoul...