recursion

Python: Expanding Complicated Tree DataStructure

让人想犯罪 __ 提交于 2019-12-25 02:04:41
问题 I am exploring a data structure which get expands to sub-elements and resolves to a final element. But I only want to store top two levels. Example: Lets say I start with New York which breaks into Bronx, Kings, New York, Queens, and Richmond as counties but then finally somehow they resolve to USA. I am not sure if this is a good example but just to make it clear here is more clear explanation of the problem. A (expands to) B,C,D -> B (expands to) K,L,M -> K resolves to Z I initially wrote

sort Array before adding to a Binary Search tree Java

霸气de小男生 提交于 2019-12-25 02:02:39
问题 I have an Array of Strings that are in order A-Z. I was wondering the best way to go about sorting them for a balanced binary search tree. My initial thought is to split the array up into the first half and the second half and then sort them individually. Shouldn't I be able to use a recursive way to keep splitting it in half to get the next Node for the tree? I just can't wrap my head around it right now and thought I would ask if any one had any ideas. to lead me in the right direction or

Recursive Query of XML in ColdFusion 8 to find unknown number of children sub levels

限于喜欢 提交于 2019-12-25 01:46:55
问题 We have a clustered ColdFusion 8 environment consisting of two boxes. I am trying to traverse XML that was created by Cognos 10.1 to find every element in the order they appear in the XML. The purpose is to create a thumbnail html representation of the report's unique layout that substitutes icons for elements. The wrinkle is that Cognos puts a new [block].[content] element for each new object in a report and then nests them based on a layered order determined when the report is created. For

Matrix transposition using recusrion

天大地大妈咪最大 提交于 2019-12-25 01:45:06
问题 Can you please give me some sort of pseudo code for matrix transposition using recursion? If it is in one function that will be great. PS: This might not be a question but I couldn't find the information anywhere. If you know of a site about pseudo codes for recursion that will be awesome. 回答1: For a square MxM matrix: function transpose (x0, y0, x1, y1) if (M > 1) transpose (0, 0, M/2, M/2) // A transpose (0, M/2, M/2, M) // B transpose (M/2, 0, M, M/2) // C transpose (M/2, M/2, M, M) // D

need help to understand recursion

孤街浪徒 提交于 2019-12-25 01:42:11
问题 n = 10 10+9+8+7+6+5+4+3+2+1 = 55 here's a piece of code to add number starting from n, to every number before it. public static int recursion(int index){ if (index == 0){ return 0; } else{ return recursion(index-1) + index; } } sorry for stupid question, but here's what confuse me: when the index is not zero, it calls the recursion function again, with the index substracted by 1, so on until the index is zero. However, it's coded recursion(index-1) + index. so why the index is not substracted

PHP: Memory leak in recursive function

a 夏天 提交于 2019-12-25 01:31:20
问题 I have a recursive function which, given an id, builds up a directory path. The thing is, it doesn't free up the space, so starting with a memory consumption of 15MB after 1761 folders, the memory consumption is at about 150MB which is not healthy. this is the function: private function buildDirectoryPath($iId, $sDir = "") { $oFolder = Folders::getFolder($iId); if (!empty($sDir)) $sDir = $oFolder->getName() . "/" . $sDir; else $sDir = $oFolder->getName(). $sDir; if ($oFolder->getParentId() >

Avoid RecursionError in turtle paint code

£可爱£侵袭症+ 提交于 2019-12-25 01:00:17
问题 I'm creating a simple program that uses turtle in a tkinter canvas to allow the user to draw with the mouse. The drawing function seems to work fine however after you draw for a bit the program stops and calls a RecursionError. from turtle import * import tkinter as tk box=tk.Tk() canv=ScrolledCanvas(box) canv.pack() screen=TurtleScreen(canv) p=RawTurtle(screen) p.speed(0) def draw(event): p.goto(event.x-256,185-event.y) #The numbers are here because otherwise the turtle draws off center.

Returned list is redundant after recursion

。_饼干妹妹 提交于 2019-12-25 00:57:27
问题 I'm new to Lisp and I have a problem when appending a list to an existing list. (Funcion spec) The following function takes 2 args; an atom and a list. The list takes 2-dimensional form where each sub-list looks like (index counter) (both index and counter are atoms). If target is equal to one of the index es, counter increments. If no sub-list contains target , add a new sub-list with counter = 1. (defun contained (target list) (cond ((null list) (list target 1)) ((= (car (car list)) target)

how to search elements in a 2d array using recursion

爱⌒轻易说出口 提交于 2019-12-25 00:35:00
问题 I have a 2d char array and I'm trying to find a specific character using recursion. public class Test { char arry [][] = {{'1',' ','B'}, {'C','K','M'}, {'H','R','P'} }; public Test(){ recursion(0,0,arry[0][0]); } private void recursion(int row, int col, char c) { if(c==' '){ System.out.print("Location: " + row + " " + col ); }else { if(col+1<arry[0].length){ recursion(row,col,c); } //System.out.print(arry[0][1]); } } public static void main(String[] args) { new Test(); } } but this is giving

Recursive algorithm for the sum of odd number positive integers

China☆狼群 提交于 2019-12-24 23:34:25
问题 I am expressing the algorithms in pseudo code. I'm just wondering if my design works just as well as the original one displayed below. The algorithm is supposed to compute the sum of n odd positive integers. This is how the algorithm should look: procedure sumofodds(n:positive integer) if n = 1 return 1 else return sumofodds(n-1) + (2n-1) This is how i designed my algorithm: procedure odd(n: positive integer) if n = 1 return 1 if n % 2 > 0 return n + odd(n-1) // this means n is odd if n % 2 =