FAQ Database Discussion Community


How to organaze data in a tree-like structure?

c#,tree
I have never used any tree structures, but now I need to make one. Here is what I am trying to do: There are five bullet point levels in PowerPoint. This is like a tree structure, but I could not find anything in powerpoint class that returns data organized in...

To print the boundary of Binary Tree

algorithm,tree,binary-tree,binary-search-tree,graph-algorithm
I have been asked in an interviews to print the boundary of the Binary Tree. For example. 1 / \ 2 3 / \ / \ 4 5 6 7 / \ \ 8 9 10 Answer will be : 1, 2, 4, 8, 9, 10, 7, 3 I have...

Building tree in Nim game

c,tree,artificial-intelligence,minimax
I want to create a game like Nim. The player can take 1 or M (defined) cubes and the winner is the player who takes the last cube. I will also create a minimax function, so the MAX player (always plays first) is making the best move. I started writing...

Recursive list split (javascript)

javascript,algorithm,tree
So say I have an array l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] which holds some set of values, in this case integers. And I have another array m: [2, 3, 2]...

K-Ary Tree Implementation in Java: how to?

java,algorithm,tree
I've a university project about creating two classes, Tree class and Node class, to implement a k-ary tree using Java. In the class Tree, there should be a constructor which recives as input an int that indicates the tree arity. I've worked before with general trees and this was my...

python tkinter tree get selected item values

python,tkinter,tree,row
I'm just starting with a small tkinter tree program in python 3.4. I'm stuck with returning the first value of the row selected. I have multiple rows with 4 columns and I am calling an a function on left-click on a item: tree.bind('<Button-1>', selectItem) The function: def selectItem(a): curItem =...

How to build a tree from a plain data structure

javascript,recursion,tree
I've the following array with objects: var arr= [{id: "1", state: "1", ndi: "1558.3045298", children: "null"}, {id: "2", state: "1", ndi: "1684.0732025", children: "null"}, {id: "3", state: "1", ndi: "1809.8418752", children: "null"}, {id: "4", state: "2", ndi: "1915.1603572", children: "null"}, {id: "5", state: "2", ndi: "2023.5463678", children: "null"}] How do...

Mapping Nested Tree With Doctrine 2 and YAML

doctrine2,tree,doctrine,yaml
We are currently working on implementing a nested tree using the DoctrineExtensions module. We believe we have wired everything up correctly, however when we go to flush using Doctrine, we keep getting an Exception. SyntaxErrorException in AbstractMySQLDriver.php line 90: An exception occurred while executing 'INSERT INTO ProductTree (left, right, rootProductTreeID,...

What is meant by complexity of O(log n)?

algorithm,data-structures,tree,binary-tree,binary-search-tree
Consider this example of binary search tree. n =10 ;and if base = 2 then log n = log2(10) = 3.321928. I am assuming it means 3.321 steps(accesses) will be required at max to search for an element. Also I assume that BST is balanced binary tree. Now to access...

Need some help making a php search tree

php,tree
Im making a tree to store words and an associated number array in php. I need it to look something like this: Words: apple, ant [a] => Array ( [p] => Array ( [p] => Array ( [l] => Array ( [e] => Array ( [0] => Array ( [0]...

JTree: How to add attributes of nodes as their own leaves?

java,xml,swing,tree,jtree
I'm visualizing XML files with javax.swing.JTree. Having used code from this and this question, I got stuck at adding attributes from a node as leaves to it. This simple XML: <?xml version="1.0" encoding="utf-8"?> <!-- comment --> <MYXML xmlns=""> <Header id=""></Header> <Product id="" name=""> <Description>Some text</Description> <Ref id=""></Ref> <Data id=""> <Ref...

How to print a tree in Python?

python,tree,pretty-print
I have the following class which represents a node of a tree: class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] # ... if parent: self.parent.children.append(self) How to print such a tree?...

D3.js collapsable tree - visualise set number of levels

javascript,jquery,d3.js,tree
I'm playing around with this example of collapsible tree: http://bl.ocks.org/mbostock/4339083 In this example initially only the root and all of its children are visualized. I was wondering how one could visualize set number of levels (for example the root and two additional levels, meaning the root, its children, and children...

How to pass variable filename to python ete?

python,variables,tree
I am trying load newick string from a file using following code: filename = templist[1].lower().replace(" ","") + ".nwk" tt = Tree(filename, format=1) but getting following error: tt = Tree(filename, format=1) # Loads a tree structure from a newick string. The returned variable tt is the root node for the tree....

RedBlack Tree Implementation

c++,algorithm,data-structures,tree
I've implemented a red-black tree and then inserted 1,2,3,4,5,6,7,8,9,10 in it. But it seems that my tree is not balanced because the pre-order traverse looks like this: 4,2,1,3,6,5,8,7,9,10 and the in-order traverse: 1,2,3,4,5,6,7,8,9,10. And that means the root is 4 and the tree is not balanced! Here is my code....

Update minimum spanning tree if edge is removed

algorithm,graph,tree,runtime,big-o
I am having trouble with the following question: Assume we have already found a minimum spanning tree T for a weighted, undirected graph G = (V,E). We would like to be able to efficiently update T should G be altered slightly. An edge is removed from G to produce a...

K-Ary Tree and Symmetric Search/Visit in Java

java,algorithm,tree
I'm dealing with a big problem: I've almost finished my first universary project, but now I'm stuck. I need to create a method (in java language) to symmetrically visit ak-ary tree (These are the words of my professor: a symmetrical visit of a k-ary tree is the symmetrical visit subtrees...

How does this code work to find the Minimum Depth of Binary Tree?

python,algorithm,tree
I see this code from https://leetcode.com/discuss/37282/simple-python-recursive-solution-bfs-o-n-80ms And it is the answer for Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. class Solution: # @param {TreeNode} root # @return...

Running trough a Tree in Java

java,recursion,tree
Basically i want to write a function that, given a Decision Tree, prints all the possible paths in the tree, and for each possible path, also prints a list of boolean values (true or false), indicating if it went left(true) or right(false) in the tree. Here's my Tree type: public...

B-Tree deletion in a single pass

algorithm,tree,b-tree
Is it possible to remove an element from a B-Tree in a single pass? Wikipedia says "Do a single pass down the tree, but before entering (visiting) a node, restructure the tree so that once the key to be deleted is encountered, it can be deleted without triggering the need...

First common element from different lists of numbers

python,list,python-2.7,tree,numbers
I am trying to find the first common number (FCN) from e.g. 5 individual number lists. For example the 5 number lists are these ones: list_1 = [13579875, 25732, 3541, 56732, 1567, 20546, 10, 68971] list_2 = [1856721, 25724, 3541, 56732, 1567, 20546, 10, 68971] list_3 = [2354074, 25732, 3541,...

Function that return average depth of a binary search tree

c,algorithm,tree,binary,binary-tree
I have the following binary tree structure, and I'd like to write a function that calculates and return the average depth of objects in a tree. Here is what I'm trying to do: calculate the total height of the tree divide total height/total nodes However, I'm getting nowhere, and would...

Making a very basic binary tree in Scala

scala,tree,binary-tree
I am trying to make a very simple binary tree in Scala for data storage and traversal. Right now I have: trait Tree case class Node(left: Tree, value: String, right: Tree) extends Tree My questions: How can I also include a pointer to a parent? Can I have left and...

Find path of given length with max weight or gain starting from source node

algorithm,graph,tree
Hello and thanks for reading this. Given a undirected tree of N vertices and e edges with associated reward point P_e, start vertex : s and an integer : M Then we have to find : Max no of points we can gain by starting at s and traversing M...

Does C have any tools for doing string addition?

c,string,algorithm,data-structures,tree
I'm making a function that returns the derivative of a function that is represented as a tree like / + \ * ^ / \ / \ x 5 3.14 x with nodes of the form typedef struct node { char * fx; // function struct node * gx; //...

'tree' and 'ls' change text color on Linux command line

linux,terminal,tree,ls
I've been having a peculiar issue caused by the tree command on Linux. When I call tree, the the color of the command prompt changes, and is only returned to normal by the ls command. I'm curious if others have encountered the same issue, and if they have fixes or...

Angular ui-grid. Error in example?

angularjs,tree,grid,angular-ui-grid
I want to use ui-grid with treeView, but in example: http://ui-grid.info/docs/#/tutorial/215_treeView it working wrong. if i click on "+" icon and then click "-" icon - last row going out from grid. How repear this, or replace to other grid with tree (hierarhical grid with several column and row selections)?...

ExtJS Put link in tree column of a tree panel

javascript,extjs,tree,extjs5
I want to put a link in a tree column from a tree panel, actually i can put the link that i want in the column but the link appears with a folder and the checkbox that i have in the other column, my question is how can delete this...

Count the number of nodes in an AVL tree in a given range

c++,algorithm,tree
I'm required to write a C++ function that, given a range (a,b], returns the number of nodes in an AVL tree that are in that given range, specifically in log(n) time complexity. I can add more fields to the tree's nodes if I need to do so. I should point...

Convert Directory Path to JSON Directory Tree Representation

c#,json,tree,filepath
I have a sample output of the file paths, this is just an example the for the question New Text Document.txt New folder/ New folder/README.txt which I would like to convert to the following JSON { "Data":"/", "Nodes":[ { "Data":"New Folder", "Nodes":[ { "Data":"New Text Document.txt" } ] }, {...

cut the tree by removing edges

java,data-structures,graph,tree,edge
Question :- removal of an edge from a given tree T will result in the formation of two separate trees, T1 and T2. Each vertex of the tree T is assigned a positive integer. Your task is to remove an edge, such that the Tree_diff of the resultant trees is...

Prefix math expressions array to parse tree - recursion to move with array

c,parsing,recursion,tree,binary-tree
I want to create a math expression parse tree from an array that is sorted in prefix notation. (BTW, will it be easier with postfix?) For example: Infix: ((((3+4)*5)/2)+8) Prefix: + 8 / 2 * 5 + 4 3 (the function will be given this) Below is my code, in...

how to auto-adjust the height of an rectangle to contain the text inside it in d3 tree

text,svg,d3.js,tree,rectangles
Hi guys i got an update in my problem........ the problem with the auto adjust of height is already solve but another problem exist as you can see in my sample if click the node that adjust the height its child overlap it.... we can use this jsfiddle for reference...

Yii 1. Get products from categories AND their subcategories [Unlimited nesting]

php,recursion,yii,tree,catalog
I'm working on some catalog based project, which contains unlimited nesting (in reality, the maximum level would be 3, I guess, but it have to be dynamic anyways). Let me show what is done: OrganizationCategory model: public function relations() { return array( 'organizations' => array(self::HAS_MANY, 'Organization', 'organization_category_id'), 'parent' => array(self::BELONGS_TO,...

Can't find certain Boost library function

c#,c++,boost,tree,nearest-neighbor
I am trying to implement a k-d tree in C# and the source I'm looking at is in C++ with Boost. The function I'm trying to find is util::subtract(). I've searched all through Boost's documentation and I can't find it anywhere. Line number 94 is the function I'm trying to...

Mutable tree to persistent tree

java,clojure,tree
Learning Clojure (and Functional Programming) I have stumbled upon the problem of converting a mutable n-ary tree represented as nested java.util.ArrayLists into a persistent tree. Using non-functional programming you would normally create the tree from the root to the leaves. This does not seem to be possible using persistent data...

Why tree is invalid?

symfony2,doctrine2,tree,doctrine-extensions,stofdoctrineextensions
I have a entity that use doctrine extension, tree behaviuor, i found problems in tree and don't know it's reason. my entity: MyEntity: type: entity gedmo: tree: type: nested id: id: type: integer generator: strategy: AUTO fields: # ... lft: type: integer gedmo: - treeLeft rgt: type: integer gedmo: -...

How to find and check all dynamic child checkboxes in tree using jquery?

javascript,jquery,dom,dynamic,tree
I have added check-boxes dynamically to all the element and successfully added the functionality to select all checkboxes but not able to do the selection for the parent child checkboxes in tree structure means if i select the "Asia" it should select all "Estern Asia" and "Southern Asia", if i...

How to build the tree if I know nodes and their parents?

scala,tree
Say I've gotten some nodes and their direct parents, like: case class Mapping(name: String, parents: Seq[String] = Nil) val mappings = Seq( Mapping("aaa"), Mapping("bbb"), Mapping("ccc"), Mapping("ddd", Seq("aaa", "bbb")), Mapping("eee", Seq("ccc")), Mapping("fff", Seq("ddd")), Mapping("ggg", Seq("aaa", "fff")), Mapping("hhh") ) How to write a function in Scala, that will build a tree based...

Search B-Tree in O(log(t)*h)

data-structures,tree
Given a B-tree such that in every node there are at most t keys and n nodes, I know that I can search the tree in O(t*h) where h is the height of the tree. Is there a way to that in O(log(t)*h)?

d3 tree very long text in indented tree how to put it in next line

javascript,d3.js,internet-explorer-8,tree,wrap
Hi i will use this jsfiddle as a reference http://jsfiddle.net/elviz/Ge58Q/13/ nodeEnter.append("text") .attr("dy", 3.5) .attr("dx", 5.5) .text(function(d) { return d.name; }); as you can see i have a node that a has a very long text i just want to ask if i reach a certain amount of text i want...

Giving unique IDs to all nodes?

python,class,tree,nodes
I am making a class in Python that relates a lot of nodes and edges together. I also have other operations that can take two separate objects and merge them into a single object of the same type, and so on. However, I need a way to give every node...

d3 indented tree close other nodes with child and open only specific node

javascript,php,d3.js,tree
Hi i will use this jsfiddle as reference http://jsfiddle.net/Ge58Q/16/ function expandSingle(d) { if (d._children) { d.children = d._children; d._children = null; } } as you can see i have a tree that has a multiple branch. What i want to do is onload i only want the NODE LIGHTNING has...

Traverse a tree from root to all children in Objective-C

objective-c,recursion,path,tree
A simplified version of what I want to do is to turn a tree like this: Into an array like this: ["abc","abd","ae"] Basically I want to traverse the tree from it's root node to each of the children. I've tried doing this by putting a for-in loop in a recursive...

Trying to create an algo that creates a spanning tree with least number of edges removed from a unweighed graph

algorithm,graph,tree,minimum-spanning-tree
I am trying to create an algo that will get a spanning tree with root node such that, the spanning tree will have least number of edges removed from Original Graph G. Thanks in advance...

LR(1) parse straight to Abstract syntax tree

java,parsing,tree,abstract-syntax-tree,lr
So I asked a question close this recently and received an very good answer. However the steps that were described seemed more like the steps to create a concrete syntax tree. Each reduction in the LR parsing process corresponds to an internal node in the parse tree. The rule being...

C - Nary Tree: error while appending a new child to the tree

c,tree,children,appendchild
I'm developing a Nary Tree in C using a structure like this: typedef struct sNaryNode { int *data; // Point to the node ’s data int n; // The number of children struct sNaryNode **child; // The child list } NaryNode; typedef NaryNode NaryTree; I can't use a List (as...

Python and XML (LandXML) [closed]

python,xml,tree,iteration
Ok, I have some XML file looks like this, actually it is LandXML file, but works like any other XML. I need to parse it with python (currently I'm using ElementTree lib) in that way to cycle through sub-element <CoordGeom></CoordGeom> and make lists dependent on child - it can be...

Adding a new branch to a tree then adding the new leaf to the right place in a linked list in an efficient way

c,algorithm,tree,binary-tree
Suppose we have a binary tree and a linked list that holds the data that appears in all of the leafs. For example, the following tree's list would be: 9,2,3 (order matter, left to right) Now we add a new node somewhere, thus creating a new branch, like so: Is...

Tree using recursive programming

c++,recursion,tree
Given a tree and some integer k, verify if the sum of the right subtree is greater than the (sum of the left subtree * k) for each subtree. The output should be a vector containing the node values for all nodes of the tree for which the above condition...

How to properly navigate an NLTK parse tree?

python,tree,nlp,nltk
NLTK is driving me nuts again. How do I properly navigate through an NLTK tree (or ParentedTree)? I would like to identify a certain leaf with the parent node "VBZ", then I would like to move from there further up the tree and to the left to identify the NP...

Statically balanced trees in Agda

tree,agda,dependent-type
I'm teaching myself about dependent types by learning Agda. Here's a type for binary trees balanced by their size. open import Data.Nat open import Data.Nat.Properties.Simple data T (A : Set) : ℕ -> Set where empty : T A 0 leaf : A -> T A 1 bal : ∀...

Scala sum of all elements in the leaves of a tree using pattern matching

scala,tree,sum,pattern-matching,case-statement
I'm learning Scala by working the exercises from the book "Scala for the Impatient". One of the questions asks: /** * Q5: One can use lists to model trees that store values only in the leaves. For example, the list ((3, 8) 2 (5)) * describes the tree * ....

Use significant attributes only, or use full set of attributes to build J48 model after checking information gain?

tree,weka,c4.5,j48
Weka's J48 allows one to check information gain on a full set of attributes, should I use those significant attributes to build my model? Or should I use the full set of attributes?

How to change the datatype of an existing tree in SML?

recursion,tree,sml,smlnj
I need to solve this problem. I really have no clue. Any help would be greatly appreciated. I guess a traversal needs to be done but I have no idea how to attack this problem. Thanks in advance. Consider again the following 1st datatype definition of a binary tree: datatype...

collapse specific nodes on load in d3 tree

jquery,d3.js,tree,collapse,expand
Hi il update my question also il included a working jsfiddle to clearly see what i want to do.... http://jsfiddle.net/elviz/Ge58Q/15/ nodeEnter.append("text") .attr("dy", 3.5) .attr("dx", 5.5) .attr("x", barWidth +20) .text(function(d) { return d.redirect_info; }) .on("click", function(d){ // using the value in d.redirect //search for the node with item_id equal to d.redirect...

Tree traversal - inorder position

java,algorithm,tree,position,traversal
I am trying to find the value of the kth node in tree, using recursive in order traversal. The code below is done with recursion, but my implementation is way too slow. Can someone please give me a hint how to make it faster? (reihe and pos are class variables,...

Designing a more efficient tree

java,algorithm,recursion,tree
Let's say we have a basic binary tree, capable of being searched recursively: class BinaryTree{ private int Element; private BinaryTree LeftNode; private BinaryTree RightNode; //Class Constructors //Class Methods } I initially learned this design of binary tree and a general tree mainly because it was simple and easy to use....

What is the most efficient way to build an unsorted binary tree in java?

java,tree,binary-tree
I need to create an unsorted binary tree (one requirement is that it is unsorted) that holds a String as its value. My class outline looks like this: public class Node { private String desc; private Node leftNode = null; private Node rightNode = null; public Node(String desc) { this.desc...

Why would one use a heap over a self balancing binary search tree?

data-structures,tree,heap,binary-search-tree,avl-tree
What are the uses of heaps? Whatever a heap can do can also be done by a self-balancing binary search tree like an AVL tree. The most common use of heap is to find the minimum (or maximum) element in O(1) time (which is always the root). This functionality can...

parent nodes value to be the sum of all its childrens

javascript,c#,recursion,tree
I've an edit tree (can change the value of the node) that isn't a binary tree, I want to store the sum of nodes values in the parent node. i.e: 50 / | \ 10 25 15 | | \ | \ 10 3 22 10 5 in the editing...

How to free memory occupied by a Tree, C?

c,tree,free
I'm currently dealing with a generic Tree with this structure: typedef struct NODE { //node's keys unsigned short *transboard; int depth; unsigned int i; unsigned int j; int player; int value; struct NODE *leftchild; //points to the first child from the left struct NODE *rightbrothers; //linked list of brothers from...

Maximum width of a Binary Tree using preorder traversal

c++,data-structures,tree,binary-tree,binary-search-tree
I want to get the maximum width of a Binary tree. In this method using Pre-order traversal width can be calculated. But I can't understand it properly. Please explain how the function getMaxWidthRecur() works. // A utility function that returns maximum value in arr[] of size n int getMax(int arr[],...

Unhandled Exception with Binary Search Tree [closed]

c++,visual-c++,tree
I have no idea what's causing it. Can you guys help me? Since last time people complained because I should only post a MCVE instead of all the source code. I'll just post what (I think) is related to the problem. It's basically a Binary Search Tree, and the unhandled...

Talend JSON structure

json,mongodb,split,tree,talend
I am struggling with my mongodboutput because I can't figure out how to build my JSON tree. Basically I have this in the "Languages" attribute of my row: Languages##English##fluent##German##beginner## I would like to have : "languages": [ { "language": "English", "level": "fluent" }, { "language": "German", "level": "beginner" } ]...

Need to convert a Result Set to some data structure

java,sql,tree,resultset
I have a java.sql.ResultSet like this: ============================= | colA | ColB | ColC | ColD | ============================= | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 2 | | 1 | 1 | 2 | 3 | | 1 | 1 | 2...

traversal method with a return value

tree,inorder
for trees, in traversal methods I want the values to be returned. the method i tried only returns one value. int inorder(BSTNode r) { int result = 0 ; if (r != null) { inorder(r.getLeft()); result= r.getData(); inorder(r.getRight()); } return result; } this code works perfectly but I want the...

Binary search tree intersection

algorithm,tree,binary-search-tree,complexity-theory
I have 2 binary search trees T1 and T2 with same number of nodes n >= 1. For each node P we have LEFT(P) and RIGHT(P) for links between nodes and KEY(P) for value off the node. The root of T1 is R1 and root of T2 is R2. I...

Navigate an NLTK tree (follow-up)

python,tree,nlp,nltk
I've asked the question how I can properly navigate through an NTLK tree. How do I properly navigate through an NLTK tree (or ParentedTree)? I would like to identify a certain leaf with the parent node "VBZ", then I would like to move from there further up the tree and...

Using Diagrams library in haskell (draw binary trees)

haskell,recursion,tree,functional-programming,binary-tree
I am trying to use the Haskell Diagrams library for drawing binary trees. This is my tree type: data Tree a = Empty | Node { label :: a, left,right :: Tree a } leaf :: a -> Tree a leaf a = Node a Empty Empty This is a...

Refresh parent node from backing bean with primefaces tree

jsf,primefaces,tree
Currently I am working on a project that use primefaces 3.4.1 version which does not support drag and drop in tree component. So I am using a contextMenu instead of drag and drop. <p:tree id="treeHierarchy" value="#{hierarchyManagementBackingBean.root}" var="node" dynamic="true" selectionMode="single" cache="false" style="width:99%;" selection="#{hierarchyManagementBackingBean.selectedNode}"> <p:treeNode id="idtreenode"> <h:outputText value="#{node.name} (#{node.entityType})" /> </p:treeNode> </p:tree>...

Expression tree data structure

c++,class,tree,expression
I want to implement a simple arithmetic expression tree data structure in c++, such that an expression tree object is initialised by: ExprTree(operator, expression1, expression2). Here is an example of how it should work: double x = 1, y = 2, z = 0.5; expr1 = ExprTree('*', x, y); //...

Creating a tree in Java

java,tree
I wrote the following tree class: public class Tree { private TreeNode root; private static class TreeNode { private Pair<String, Float> data; private TreeNode leftNode; private TreeNode rightNode; private TreeNode( Pair<String, Float> data, TreeNode left, TreeNode right) { this.data = data; this.leftNode = left; this. rightNode = right; } }...

prolog traverse nonstandard tree left to right

tree,prolog,tree-traversal
I need to implement a predicate trav(Tree,List) that performs a left to right tree traversal; Where: Tree is defined by the structure node(left,right), where left and right can be either another node or any Prolog data item. List is the list of leaf node values in the tree. For example:...

recursively editing member variable: All instances have same value

python-3.x,recursion,tree,member
I want to create a Tree data structure that consists of TreeNode objects. The root is a TreeNode. Each TreeNode has one parent TreeNode and a list of children TreeNodes. The Tree is built up recursively. I simplified the code to make the example not too difficult. The function get_list_of_values_from_somewhere...

using local storage saved value as a text in a root text

extjs,tree,local-storage,store
I have a treeView in my extjs View, in which I need to give the the value of a local storage variable as the root name.The value to the local storage is fed when user logins successfully : Ext.define('Eits.view.OrgTreeView', { extend : 'Ext.tree.TreePanel', requires: ['Eits.model.OrgTreeModel'], width : '100%', region :...

How to use Expression Tree to safely access path of nullable objects?

c#,lambda,path,tree,expression-trees
When I get deserialized XML result into xsd-generated tree of objects and want to use some deep object inside that tree a.b.c.d.e.f, it will give me exception if any node on that query path is missing. if(a.b.c.d.e.f != null) Console.Write("ok"); I want to avoid checking for null for each level...

Specifying nodeSize for each node individually in D3.js tree layout

javascript,d3.js,tree,spacing
How do I set the nodeSize for the D3 tree layout for each node individually? In my case I have a tree containing nodes of varying sizes and setting d3.layout.tree().nodeSize([300, 200]); results in weird spacing when the width of nodes varies. nodeSize seems to be one of the few D3...

Find root of minimal height which is not BST

algorithm,data-structures,tree,binary-tree,binary-search-tree
I'm struggling with following problem: Write function which for given binary tree returns a root of minimal height which is not BST or NIL when tree is BST. I know how to check if tree is BST but don't know how to rewrite it. I would be grateful for an...

Binary red black tree, best way to walk back to root?

c#,algorithm,tree
I'm in the processes of building a binary red black tree. One issue I'm seeing is in rotations and moving backwards to parent nodes to find black red violations after doing rotations. I don't want to search the tree again for the last node, so I have started using a...

Tree structure - incorrect children

c++,tree
I'm trying to build simple structure in C++. It should be similar to AVL tree. Everything is OK when I build a simple tree with three nodes in main() function. The problem is when I try use insert() function. The first argument of this function contains information where put the...

Trie Data Structure in Finding an Optimal Solution

java,algorithm,data-structures,tree,trie
This Question is part of ongoing Competition , I have solved the 75% of this Question Data Set but the 25% is giving me TLE. I am asking why it's is giving TLE an i am sure my complexity is O(n*n)Question: String S consisting of N lowercase English alphabets. We...

Using a survival tree from the 'rpart' package in R to predict new observations

r,tree,survival-analysis,rpart
I'm attempting to use the "rpart" package in R to build a survival tree, and I'm hoping to use this tree to then make predictions for other observations. I know there have been a lot of SO questions involving rpart and prediction; however, I have not been able to find...

how can an objects points on many other objects in JAVA?

java,pointers,tree,trie
I'm trying to build a TRIE, but for that I need that the root of the tree would be able to point on sons as much as I want to create (since it's supposed to use as Prefix tree). So I'd like to know if it is even possible make...

Transform flat array of objects intro tree [closed]

php,arrays,parsing,tree
I have a flat array of objects like this: [ { id: "a", parent-id: "" }, { id: "b", parent-id: "a" }, { id: "c", parent-id: "b" }, { id: "d", parent-id: "" }, ... ] I would like to parse this flat array into a tree-structure, where objects with...

How to copy an object in Scala?

scala,tree,copy,binary-tree
I have this tree structure sealed trait Tree case class Node(var left: Tree, var right: Tree, var value: String) extends Tree case object EmptyNode extends Tree and a Tree object called myTree. I want to make another tree with the exact same structure and values called otherTree, but myTree.clone() does...

How to add items to ComboBox as tree list

c#,winforms,combobox,tree
I have problem: I want show items in ComboBox as they are categorized. As shown in figure: I have two attributes in my table , one is vendorID , the other is vendorType . I want to show these vendor types in the ComboBox How I should do this?...

Print in tree format in smart loop

php,tree
I have a array of date and name; I need to show it in tree structure in a minimum code. $myarray = Array ( [0] => Array ( 'Name' => 'Ron', 'date' => '2014-01-05' ) [1] => Array ( 'Name' => 'Sam', 'Value' => '2014-01-10' ) [2] => Array (...

Dynamically generated nested tree object from array

javascript,object,tree
Given these two strings, '1|100376|100377|100378' and '1|100376|100377|100379|100380' I want to create an object that looks like this: { id:"1", children: { id:"100376", children: { id:"100377", children: { id:"100378", children: {}, id: "100379", children: { id:"100380", children: {} } } } } } Here is the code I have, var tree...

Java: make prefix tree remember last value that was not null

java,tree,prefix,trie
I have code for prefix tree (Trie) like this: public class Trie<V> { Entry<V> entry; char key; Map<Character, Trie<V>> childrens; public Trie() { this.childrens = new HashMap<Character, Trie<V>>(10); entry = new Entry<V>(); } /** non-public, used by _put() */ Trie(char key) { this.childrens = new HashMap<Character, Trie<V>>(10); this.key = key;...

Print a Pretty Tree

python-3.x,tree,bfs
I have extracted a list from a tree using BFS solution= [[6], [0, 7], [None, 3, None, 8], [2, 5, None, 9], [1, None, 4, None, None, None], [None, None, None, None]] How do i print it as a horizontal tree? I was trying to print it using def _print_tree(n=0,height,solution):...

Python access mother class fields

python,tree,iterator,instance
While writing an iterator for a tree class in python I stumbled upon the issue, that I apparently cannot access fields and methods of the mother class without instanciating an iterator instance with a reference to an already existing Tree instance, so I always need to call the iterator like...

C - deleting n-ary tree nodes

c,tree,delete,n-ary-tree
I have implemented in C an m,n,k-game with AI. The game works fine but when I have to free the decision tree it always throws an "Access violation reading location" exception. This is the implementation of the decision tree structure: typedef struct decision_tree_s { unsigned short **board; status_t status; struct...

Given a BST, and a node in BST, make that node, as new root of the tree

algorithm,data-structures,tree,binary-search-tree
Given a BST, and a node in BST, make that node, as new root of the tree. But still maintain the tree as BST after making this node as root. I tried as follows: Take given node as root, if its on left of original root then make original root...

Tree searching algorithm

string,algorithm,search,graph,tree
I'm looking for suggestions on strategies for searching a tree-like data structure. The structure is a tree where each element is a string, each branch is a period, and a path is the concatenation of several strings and periods starting at the root. The root and edges from the root...

How to fetch the child of JSON data using jquery tree structure

javascript,jquery,json,tree
I have tried the below code to fetch the data but unable to fetch the child. var data= [ { "name": "India", "region": "Asia" }, { "name": "Sri Lanka", "region": "Asia" }, { "name": "Maldives", "region": "Asia" }, { "name": "China", "region": "Asia", "subRegion": [ { "name": "Central China" },...

Update minimum spanning tree if edge is added

algorithm,graph,tree,runtime,big-o
I have a possible solution for the following question, but not sure if correct: Assume we have already found a minimum spanning tree T for a weighted, undirected graph G = (V,E). We would like to be able to efficiently update T should G be altered slightly. An edge is...

Deletion from B-Tree - M=5

algorithm,tree,b-tree
I'm dealing with a deletion in BTree in very specific case M=5 - that is - maximum number of keys in node is 4 and minimum number of keys in node is 2 Now when deleting in BTree using the defensive approach (I must use this one) when I approach...

adding integers from each node of a tree

c,recursion,struct,tree
How would I be able to add data from different nodes together? Inserttotree() just creates a new node and enters the data value specified. So basically I'm just trying to add 2 and 3 together in the countquantity() function. typedef struct tree_s tree_t; typedef int data_t; struct tree_s { data_t...

dijit tree not able to get child from collapase tree

tree,dojo,children
My dojo tree is very huge. I need to expand one node at time to increase the performance. My tree have check box. When one check a parent node , I need to know all the child of the parent , also the sub child till the leaf of the...