Questions tagged [tree]

A tree is a widely-used data structure that emulates a hierarchical tree-like structure with a set of linked nodes.

A tree is a data structure where each node has a number of child nodes. By starting at the first node (called the root), one can use a decision algorithm to determine which of the children of the current node is the most appropriate for the next processing or traversal step.

Operations on trees include insert, delete, traverse and find. The algorithms for these methods are usually recursive, starting from the root node and recursively calling its left and right child.

Below is an example of binary-tree, in which each node has up to two child nodes:

binary tree

Because large portions of the remaining nodes are culled away with each decision, properly balanced trees typical yield logarithmic time lookups, inserts, and deletes when used for storage.


Useful links


Related tags

16659 questions
54
votes
9 answers

create array tree from array list

i have a list like this: array( array(id=>100, parentid=>0, name=>'a'), array(id=>101, parentid=>100, name=>'a'), array(id=>102, parentid=>101, name=>'a'), array(id=>103, parentid=>101, name=>'a'), ) but way bigger so i need a efficient way…
Thunderstriker
  • 1,279
  • 1
  • 11
  • 11
54
votes
5 answers

Is there pointer in C# like C++? Is it safe?

I'm writing an application that work with a tree data structure. I've written it with C++, now i want to write it by C#. I use pointers for implementing the tree data structure. Is there a pointer in C# too? Is it safe to use it?
masoud ramezani
  • 22,228
  • 29
  • 98
  • 151
53
votes
6 answers

What javascript tree data structures are available?

Are there good libraries for manipulating trees in javascript? Just to be clear, I am looking for tree as in data structure not display model.
tallowen
  • 4,198
  • 7
  • 27
  • 35
53
votes
4 answers

What is the difference between a node and a vertex?

What is the difference (if any) between a node and a vertex? I can't find the answer after looking at countless sites! Even my book doesn't specify it so I am kind of lost! It is worth mentioning that I am looking for the difference besides the fact…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
52
votes
12 answers

Storing a large number of images

I'm thinking about developing my own PHP based gallery for storing lots of pictures, maybe in the tens of thousands. At the database I'll point to the url of the image, but here's the problem: I know is impractical to have all of them sitting at the…
Saiyine
  • 1,579
  • 3
  • 15
  • 27
51
votes
11 answers

Hashing a Tree Structure

I've just come across a scenario in my project where it I need to compare different tree objects for equality with already known instances, and have considered that some sort of hashing algorithm that operates on an arbitrary tree would be very…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
51
votes
6 answers

Handling inheritance with overriding efficiently

I have the following two data structures. First, a list of properties applied to object triples: Object1 Object2 Object3 Property Value O1 O2 O3 P1 "abc" O1 O2 O3 P2 "xyz" O1 O3 O4 …
Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172
50
votes
5 answers

tree command on osx bash

I'm following a screen cast on a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command. It does not appear to be working on my system: [24] pry(main)> .tree \Error: there was a problem executing system command:…
JZ.
  • 21,147
  • 32
  • 115
  • 192
50
votes
6 answers

Binary Search Tree - Java Implementation

I'm writing a program that utilizes a binary search tree to store data. In a previous program (unrelated), I was able to implement a linked list using an implementation provided with Java SE6. Is there something similar for a binary search tree, or…
user1696230
49
votes
4 answers

Applications of red-black trees

What are the applications of red-black (RB) trees? Is there any application where only RB Trees can be used and no other data structures?
krackoder
  • 2,841
  • 7
  • 42
  • 51
48
votes
11 answers

Hash table vs Balanced binary tree

What factors should I take into account when I need to choose between a hash table or a balanced binary tree in order to implement a set or an associative array?
peoro
  • 25,562
  • 20
  • 98
  • 150
48
votes
6 answers

What's a good and stable C++ tree implementation?

I'm wondering if anyone can recommend a good C++ tree implementation, hopefully one that is stl compatible if at all possible. For the record, I've written tree algorithms many times before, and I know it can be fun, but I want to be pragmatic and…
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
47
votes
3 answers

Construct a minimum spanning tree covering a specific subset of the vertices

I have an undirected, positive-edge-weight graph (V,E) for which I want a minimum spanning tree covering a subset k of vertices V (the Steiner tree problem). I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k…
atp
  • 30,132
  • 47
  • 125
  • 187
46
votes
9 answers

Family Tree Algorithm

I'm working on putting together a problem set for an intro-level CS course and came up with a question that, on the surface, seems very simple: You are given a list of people with the names of their parents, their birth dates, and their death…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
46
votes
6 answers

How to create a collapsing tree table in html/css/js?

I have some data to display that is both tabular and hierarchical. I'd like to let the user be able to expand and collapse the nodes. Sort of like this, except functional: http://www.maxdesign.com.au/articles/tree-table/ What would be the best way…
justkevin
  • 3,089
  • 3
  • 28
  • 33