tree

Most efficient data structure to represent threaded comments in Java?

I want to represent threaded comments in Java. This would look similar to the way comments are threaded on reddit.com hello hello hello hello hello hello hello As in the example above, responses are nested in the HTML with appropriate indentation to reflect their relationship to prior comments. What would b...

Flex: Expand AdvancedDataGrid Tree Column programatically

Does anyone know how to programmatically expand the nodes of an AdvancedDataGrid tree column in Flex? If I was using a tree I would use something like this: dataGrid.expandItem(treeNodeObject, true); But I don't seem to have access to this property in the AdvancedDataGrid. Thanks for your help! ...

How do I test whether a tree has a perfect matching in linear time?

Give a linear-time algorithm to test whether a tree has a perfect matching, that is, a set of edges that touches each vertext of the tree exactly once. This is from Algorithms by S. Dasgupta, and I just can't seem to nail this problem down. I know I need to use a greedy approach in some manner, but I just can't figure this out. Help?...

Creating a tree from a list of tuples

I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that (id, parent_id, value) So that it is a representation of the tree as a flattend list of list of tree nodes. For example the input (1, None, '...') (3, 2', '...') (2, 1, '...') (4, 1, '...') (5, 2, '...') (6, None, '...') S...

PHP: How to generate a <ul><li> tree in an xml2assoc array result?

Hi, I have seen many PHP function on how to generate a <ul><li> tag but my array input is quite complicated I guess. It is an array returned from a custom function called xml2assoc My question is how can I convert the returned xml2assoc array result to a <ul><li> formatted HTML code using PHP. Thanks. $tree = array( 0 => array( ...

What the best way to handle categories, sub-categories - hierachical data?

Duplicate: SQL - how to store and navigate hierarchies If I have a database where the client requires categories, sub-categories, sub-sub-categories and so on, what's the best way to do that? If they only needed three, and always knew they'd need three I could just create three tables cat, subcat, subsubcat, or the like. But wh...

Iterating over a Binary Tree with O(1) Auxiliary Space

Is it possible to iterate over a binary tree in O(1) auxiliary space (w/o using a stack, queue, etc.), or has this been proven impossible? If it is possible, how can it be done? Edit: The responses I've gotten about this being possible if there are pointers to parent nodes are interesting and I didn't know that this could be done, but...

Fluent interfaces / extension methods - Turning a flat list into a navigation tree

I currently have an extension Method which converts an IEnumerable of type Tab into a hierarchical collection of TabNodes. // If Tab has no parent its ParentId is -1 public class Tab { public int TabId { get; set; } public string TabName { get; set; } public int Level { get; set; } public int ParentId { get; set; } } publ...

Display a list of nodes in a TreeView

Hi there, I have an node object which specifies the node level public class Node { public int Level { get; set; } } I want to use an ordered list of nodes to construct a treeview var nodes = new[] { new Node(){Level = 0}, new Node(){Level = 1}, new Node(){Level = 1}, new Node(){Level = 1}, ...

How to convert this MPTT array into a tree structure in PHP?

I've got hierarchal data in the database, stored in Modified Preorder Tree Traversal format. I'm pulling the data in a query that looks something like "SELECT ID, Left, Right, Name, etc FROM Table ORDER BY Left;". I'm trying to convert this data from a flat array the DB gives me into a tree-structure which I will then output as JSON wi...

Binary word trees

I have barely squeaked by my last cs class and now I am in data structures. I am building a binary tree structure from scratch and I am a little confused on how the iterator will work. I understand how they work in double linked lists, but am not sure how this one will work................ thanks. ...

Write a linq expression to select a subtree of items

Given a class: class Control { public Control Parent { get; set; } public List<Control> Children { get; set; } } and a list: List<Control> myControls; Is it possible to write a linq query that will select all children & grandchildren for a given control? For example if a tree looks like this: GridA1 PanelA1 TextBoxA...

Rich Faces Tree Control for handheld device

Currently I have a rich tree which works as expected; however the tree itself is not appropriate for small devices where you use your finger for navigation. The arrow that represents the child nodes, and their expansion, is too small. Is there any way to change that graphic, or increase its size? ...

Binary tree remove method

I am doing some extra work in my computer science class trying to get better at understanding the logic of data structures. Specifically, I am trying to write a remove function for a sorted binary tree: private boolean remove(Node cRoot, Object o) { if (cRoot == null) { return false; } else if (cRoot.item.equals(o)) { //e...

How to implement a tree structure, but still be able to reference it as a flat array by index?

I want to have a tree in memory, where each node can have multiple children. I would also need to reference this tree as a flat structure by index. for example: a1 b1 b2 b3 c1 d1 e1 e2 d2 f1 Would be represented as a flat structure as I laid out (i.e.; a1=0, b1=...

Convert a XML Schema (XSD) document to a tree like structure

Hi Guys, I am in real trouble. I want to convert an XML schema (XSD) document into a tree like structure. Is there any straight way of doing it? I used XMLBeans to parse the XSD document and tried to traverse the parsed document. But, handling the gory details of XSD was not easy. Thereby, I left that and searching for a much cleaner wa...

Fast Relational method of storing tree data (for instance threaded comments on articles)

I have a cms which stores comments against articles. These comments can be both threaded and non threaded. Although technically they are the same just with the reply column left blank when it's not threaded. My application works on sqlLite, MySQL and pgsql so I need fairly standard SQL. I currently have a comment table comment_id artic...

SwingWorker to update TreeModel?

Hello, I've got lots of JTree in my app, all using different instances (with different options) of the same custom TreeModel class. I'm trying to add some threading to speed things up, since the getChildren() member takes a while to run, I added a SwingWorker subclass to the TreeModel and in my getChildren() I create an instance of that...

How to implement high performance tree view in SQL Server 2005

What is the best way to build the table that will represent the tree? I want to implement a select ,insert ,update and delete that will work well with big data. The select for example will have to support "Expand ALL" - getting all the children (and there children) for a given node. ...

Multiple parents tree (or digraph) implementation sql server 2005

Hi guys, I need to implement a multi-parented tree (or digraph) onto SQL Server 2005. I've read several articles, but most of them uses single-parented trees with a unique root like the following one. -My PC -Drive C -Documents and Settings -Program Files -Adobe -Microsoft -Folder X -Drive D ...