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
87
votes
13 answers

Difference between "Complete binary tree", "strict binary tree","full binary Tree"?

I am confused about the terminology of the below trees, I have been studying the Tree, and I am unable to distinguish between these trees: a) Complete Binary Tree b) Strict Binary Tree c) Full Binary Tree Please help me to differentiate among these…
kTiwari
  • 1,488
  • 1
  • 14
  • 21
84
votes
8 answers

When to use Binary Space Partitioning, Quadtree, Octree?

I have recently learned about binary space partitioning trees and their application to 3d graphics and collision detection. I have also briefly perused material relating to quadtrees and octrees. When would you use quadtrees over bsp trees, or…
Martin
  • 5,945
  • 7
  • 50
  • 77
84
votes
9 answers

Difference between red-black trees and AVL trees

Can someone please explain what the main differences between these two data structures are? I've been trying to find a source online that highlights the differences/similarities, but I haven't found anything too informative. In what cases would…
Bob John
  • 3,688
  • 14
  • 43
  • 57
83
votes
4 answers

Difference between Tries and Trees?

I remotely remember that tries don't store the whole data per node, only the suffix to the parent node. Where trees do store the whole data, but only organize themselves based on a prefix. So tries get smaller, which allows for example to compress…
The Surrican
  • 29,118
  • 24
  • 122
  • 168
78
votes
11 answers

How to search JSON tree with jQuery

I have a question about searching the JSON for the specific information. For example, I have this JSON file: { "people": { "person": [ { "name": "Peter", "age": 43, "sex":…
Mentalhead
  • 1,501
  • 5
  • 20
  • 28
78
votes
13 answers

What type of NoSQL database is best suited to store hierarchical data?

What type of NoSQL database is best suited to store hierarchical data? Say for example I want to store posts of a forum with a tree structure: original post + re: original post + re: original post + re2: original post + re3: original post …
deamon
  • 89,107
  • 111
  • 320
  • 448
77
votes
6 answers

Tree plotting in Python

I want to plot trees using Python. Decision trees, Organizational charts, etc. Any library that helps me with that?
Injeniero Barsa
  • 1,085
  • 2
  • 10
  • 12
70
votes
6 answers

Hitting Maximum Recursion Depth Using Pickle / cPickle

The background: I'm building a trie to represent a dictionary, using a minimal construction algorithm. The input list is 4.3M utf-8 strings, sorted lexicographically. The resulting graph is acyclic and has a maximum depth of 638 nodes. The first…
danben
  • 80,905
  • 18
  • 123
  • 145
69
votes
4 answers

Makefile issue: smart way to scan directory tree for .c files

I am doing a project which is growing pretty fast and keeping the object files up date is no option. The problem beyond wildcard command lies somewhere between "I do not want recursive makefiles" and "I do not want it to list by hand". The objects…
drahnr
  • 6,782
  • 5
  • 48
  • 75
66
votes
9 answers

How to represent a data tree in SQL?

I'm writing a data tree structure that is combined from a Tree and a TreeNode. Tree will contain the root and the top level actions on the data. I'm using a UI library to present the tree in a windows form where I can bind the tree to the…
Avi Harush
  • 989
  • 2
  • 10
  • 15
59
votes
6 answers

Why Java Collection Framework doesn't contain Tree and Graph

I am familiar with Java Collection Framework which contains basic interfaces: Collection and Map. I am wondering why the Framework doesn't contain structures as Tree and Graph which are basic collections. Both can be regarded as sub types of…
卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130
58
votes
8 answers

How do I print out a tree structure?

I'm trying to improve performance in our app. I've got performance information in the form of a tree of calls, with the following node class: public class Node { public string Name; // method name public decimal Time; // time spent in…
Simon
  • 25,468
  • 44
  • 152
  • 266
56
votes
4 answers

What are the known ways to store a tree structure in a relational DB?

There is the "put a FK to your parent" method, i.e. each records points to it's parent. Which is a hard for read actions but very easy to maintain. And then there is a "directory structure key" method: 0001.0000.0000.0000 main branch…
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
55
votes
14 answers

Build a tree from a flat array in PHP

I've looked around the internet and haven't quite found what I'm looking for. I have a flat array with each element containing an 'id' and a 'parent_id'. Each element will only have ONE parent, but may have multiple children. If the parent_id = 0,…
DSkinner
  • 593
  • 1
  • 4
  • 7
54
votes
19 answers

Python: simple list merging based on intersections

Consider there are some lists of integers as: #-------------------------------------- 0 [0,1,3] 1 [1,0,3,4,5,10,...] 2 [2,8] 3 [3,1,0,...] ... n [] #-------------------------------------- The question is to merge lists having at least one common…
Developer
  • 8,258
  • 8
  • 49
  • 58