recursion

Recursively sort array to levels

Hi, I've been working on a site that uses binary mlm system. Illustration here So I have a two tables in database, users anad relationships. There is ID and personal data columns in users. Relationships has 4 columns: ID, parentID, childID, pos. Where pos is either left or right. I have succesfully written a function that recursively...

Bubble sort using recursion in C#

Hey there! I've wrote this simple piece of code. And I have a slight problem with it. int [] x = [50,70,10,12,129]; sort(x, 0,1); sort(x, 1,2); sort(x, 2,3); sort(x, 3,4); for(int i =0; i<5; i++) Console.WriteLine(x[i]); static int [] sort(int [] x, int i, int j){ if(j ==x.length) return x; else if(x[i]>x[j]){ int temp = x[i]; x[i] = x[...

Traverse 2D Array in Spiral pattern using recursion.

Hi, I am preparing for an interview and have been stuck on this question for quite some time now. Could anybody please help me with the code. If not complete then may be a snippet of it? Please.. ...

How can be implemented recursive regexp in python?

I'm interested how can be implemented recursive regexp matching in Python (I've not found any examples :( ). For example how would one write expression which matches "bracket balanced" string like "foo(bar(bar(foo)))(foo1)bar1" ...

How to retrieve tree nodes children (recursive function help)

I have a binary, the database table of relationships looks like this: +----+----------+---------+-----+ | id | parentID | childID | pos | +----+----------+---------+-----+ | 1 | 1 | 2 | l | | 2 | 1 | 3 | r | | 3 | 2 | 4 | l | | 4 | 3 | 5 | r | | 5 | 4 | 6 | l ...

In Haskell, how do I recursively manipulate a tuple and preappend a character to the first element in the tuple?

The type of this function is function :: Num a => ([Char],a) -> ([Char],a) My input for this function would be something like function (".'*",0) and the function finds the first '.' or '*' and updates a, by adding 200 or 400 to a's value depending on which character was replaced first. Once something is changed, the rest of the charact...

Issues with maps and their entries in Scala

I have a recursive function that takes a Map as single parameter. It then adds new entries to that Map and calls itself with this larger Map. Please ignore the return values for now. The function isn't finished yet. Here's the code: def breadthFirstHelper( found: Map[AIS_State,(Option[AIS_State], Int)] ): List[AIS_State] = { val exten...

Clojure: Simple factorial causes stack overflow

What am i doing wrong? Simple recursion of few thousand deep throws "StackOverflowError" If the limit of Clojure recursions is so low, how can I rely on it ? (defn fact[x] (if (<= x 1) 1 (* x (fact (- x 1)) ))) user=> (fact 2) 2 user=> (fact 4) 24 user=> (fact 4000) java.lang.StackOverflowError (NO_SOURCE_FILE:0) ...

SQL Server Database Design Problem/Challenge

I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID NodeTypeID NodeName ... NodeType Table NodeTypeID ParentNodeTypeID NodeTypeName ..... Both tables have a relationship to itself. There are different types of node i.e Node Site Building Office These are hierarchical, so information (attributes) th...

Selection sort in functional Scala

I'm making my way through "Programming in Scala" and wrote a quick implementation of the selection sort algorithm. However, since I'm still a bit green in functional programming, I'm having trouble translating to a more Scala-ish style. For the Scala programmers out there, how can I do this using Lists and vals rather than falling back i...

Linked list Recursion

Hi everyone. So, I was reading about linked lists and recursion. I just wanted to know why can't I use recursion in a method that is static void? Also, I was wondering in Java in the linked list recursion, why you can use static void in printing or search for the nodes. Thank you. ...

How to find recursion in your app?

My c# service got an internal .net execution error that points to recursion issue (e.g. stack overflow). The problem is that the service is pretty large, so I am having trouble finding where the recursion actually occurs. Can someone with massive regex mojo hook me up with a search string that would find what I need? ...

SQL Server: How to get all child records given a parent id in a self referencing table

Hi I have a which references itself and I need to be able to select the parent and all it's child records from a given parent Id. My table is as follows: ID | ParentID | Name ----------------------- 1 NULL A 2 1 B-1 3 1 B-2 4 2 C-1 5 2 C-2 So ...

django recursive relationships

My DjangoApp is using categories to generate a navigation and to put stuff in those categories. There are two types of categories: ParentCategories (top categories) ChildCategories (sub categories that have a ParentCategory as a parent) Because those to categories are so similar I don't want to use two different models. This is my c...

Selecting records during recursive stored procedure

I've got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that's retrieved by a (rather large) series of queries...but I'm attempting to speed things up by using a recursive stored procedure. (As I understanding, using CT...

recursive function error

I have a program that is supposed to read in values from user into a vector. My function is then supposed to keep a running sum and start from element 1 and compare element 2 to the sum(this point it is just element 1). Move to the next element, add element 2 to the sum and see if element 3 is greater than the sum of elements 1 and 2. ...

Recursion and permutations

Hi. Let's say that we have two boxes of pencils (in first box just blue and in second just red pencils). So the question now is, in how many ways can we put x red and y blue pencils in the line? Example: we have 3 Red pencils, and 1 Blue. Then we have 4 different ways. Combinations: BRRR, RBRR, RRBR, RRRB. So with 10 Red and 10 Blue ...

Create a recursive function to print integer numbers vertically.

Create a recursive function to print a multidigit number vertically. For example, 2378 should be printed 2 3 7 8 Test your program with numbers of different length. ...

Python: How to replace dashes in filenames?

The question is related to the answer about renaming files recursively. The code, changed to replace dashes, does not work with cases such as: ./Beginners Tools/Hello's -Trojans-/bif43243 ./Linux/Nux Col - 1 Works (TEX & Pdf) - T'eouhsoe & More (33323 - 34432) ./Git/peepcode-git-mov/c6_branch_merge.mov ./haskell/OS 2007 - T aoue ./B Si...

c# recursive generics data structure searching

Hi folks, been struggling with this for a couple of days now and still stumped. i have a data structure that starts with containers that can hold other containers, and eventually leaf nodes. i'm looking for a way of being to iterate thru elements of a type directly, without pulling them into another collection so i can operate on them i...