All Topics  
Tree (data structure)

 

   Email Print
   Bookmark   Link






 

Tree (data structure)



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, a tree is a widely-used data structure
Data structure

A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data....
 that emulates a hierarchical tree structure
Tree structure

A tree structure is a way of representing the hierarchy nature of a structure in a graphical form.It is named a "tree structure" because the graph looks a bit like a tree, even though the tree is generally shown upside down compared with a real tree; that is to say with the root at the top and the leaves at the bottom....
 with a set of linked nodes
Vertex (graph theory)

In graph theory, a vertex or node is the fundamental unit out of which graphs are formed: an undirected graph consists of a set of vertices and a set of edges , while a directed graph consists of a set of vertices and a set of arcs ....
. It is an acyclic connected graph
Graph (mathematics)

In mathematics a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges....
 where each node has a set of zero or more children nodes, and at most one parent node.

de may contain a value or a condition or represent a separate data structure or a tree of its own.






Discussion
Ask a question about 'Tree (data structure)'
Start a new discussion about 'Tree (data structure)'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Binary Tree
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, a tree is a widely-used data structure
Data structure

A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data....
 that emulates a hierarchical tree structure
Tree structure

A tree structure is a way of representing the hierarchy nature of a structure in a graphical form.It is named a "tree structure" because the graph looks a bit like a tree, even though the tree is generally shown upside down compared with a real tree; that is to say with the root at the top and the leaves at the bottom....
 with a set of linked nodes
Vertex (graph theory)

In graph theory, a vertex or node is the fundamental unit out of which graphs are formed: an undirected graph consists of a set of vertices and a set of edges , while a directed graph consists of a set of vertices and a set of arcs ....
. It is an acyclic connected graph
Graph (mathematics)

In mathematics a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges....
 where each node has a set of zero or more children nodes, and at most one parent node.

Terminology

A node may contain a value or a condition or represent a separate data structure or a tree of its own. Each node in a tree has zero or more child nodes, which are below it in the tree (by convention, trees grow down, not up as they do in nature). A node that has a child is called the child's parent node (or ancestor node, or superior
Superior (hierarchy)

In a hierarchy or tree structure of any kind, a superior is an individual or position at a higher level in the hierarchy than another , and thus closer to the Apex ....
). A node has at most one parent.

The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. The depth of a node is the length of the path to its root (i.e., its root path). This is commonly needed in the manipulation of the various self balancing trees, AVL Trees in particular. Conventionally, the value -1 corresponds to a subtree with no nodes, whereas zero corresponds to a subtree with one node.

The topmost node in a tree is called the root node. Being the topmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin (although some algorithms begin with the leaf nodes and work up ending at the root). All other nodes can be reached from it by following edges or links. (In the formal definition, each such path is also unique). In diagrams, it is typically drawn at the top. In some trees, such as heap
Heap (data structure)

In computer science, a heap is a specialized tree data structure-based data structure that satisfies the heap property: if B is a child node of A, then key ≥ key....
s, the root node has special properties. Every node in a tree can be seen as the root node of the subtree rooted at that node.

Nodes at the bottommost level of the tree are called leaf node
Leaf node

In computer science, a leaf node or external node is a node of a tree data structure that has zero child nodes. Often, leaf nodes are the nodes farthest from the root node....
s
. Since they are at the bottommost level, they do not have any children. They are also referred to as terminal nodes.

An internal node or inner node is any node
Node (computer science)

A node is an abstract basic unit used to build linked data structures such as tree data structure, linked lists, and computer-based representations of graph ....
 of a tree that has child nodes and is thus not a leaf node
Leaf node

In computer science, a leaf node or external node is a node of a tree data structure that has zero child nodes. Often, leaf nodes are the nodes farthest from the root node....
.

A subtree is a portion of a tree data structure that can be viewed as a complete tree in itself. Any node in a tree T, together with all the nodes below it, comprise a subtree of T. The subtree corresponding to the root node is the entire tree; the subtree corresponding to any other node is called is a proper subtree (in analogy to the term proper subset).

Tree ordering

There are two basic types of trees. In a recursive tree or unordered tree, a tree is a tree in a purely structural sense — that is to say, given a node, there is no order for the children of that node. A tree on which an order is imposed — for example, by assigning different natural numbers to each edge leading to a node's children — is called an edge-labeled tree or an ordered tree with data structures built upon them being called ordered tree data structures.

Ordered trees are by far the most common form of tree data structure. Binary tree
Binary tree

In computer science, a binary tree is a Tree in which each node has at most two child node. Typically the child nodes are called left and right....
s are one kind of ordered tree because the childrens are ordered as left and right child.

Tree representations

There are many different ways to represent trees; common representations represent the nodes as records allocated on the heap (not to be confused with the heap data structure
Heap (data structure)

In computer science, a heap is a specialized tree data structure-based data structure that satisfies the heap property: if B is a child node of A, then key ≥ key....
) with pointers to their children, their parents, or both, or as items in an array
Array

In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory....
, with relationships between them determined by their positions in the array (e.g., binary heap
Binary heap

A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints:*The shape property: the tree is a complete binary tree; that is, all levels of the tree, except possibly the last one are fully filled, and, if the last level of the tree is not complete, the node...
).

Trees as graphs

In graph theory
Graph theory

In mathematics and computer science, graph theory is the study of graph : mathematical structures used to model pairwise relations between objects from a certain collection....
, a tree
Tree (graph theory)

In mathematics, more specifically graph theory, a tree is a graph in which any two Vertex are connected by exactly one path . Alternatively, any connectedness graph with no Cycle is a tree....
 is a connected acyclic
Acyclic

Acyclic can refer to:* in chemistry, a compound which is not Cyclic compound, e.g. alkanes and acyclic aliphatic compounds* in mathematics:** a directed acyclic graph...
 graph
Graph (data structure)

In computer science, a graph is a kind of data structure, specifically an abstract data type , that consists of a Set of nodes and a set of edges that establish relationships between the nodes....
. A rooted tree is such a graph with a vertex
Vertex (graph theory)

In graph theory, a vertex or node is the fundamental unit out of which graphs are formed: an undirected graph consists of a set of vertices and a set of edges , while a directed graph consists of a set of vertices and a set of arcs ....
 singled out as the root. In this case, any two vertices connected by an edge inherit a parent-child relationship. An acyclic graph with multiple connected components or a set of rooted trees is sometimes called a forest.

Traversal methods

Stepping through the items of a tree, by means of the connections between parents and children, is called
walking the tree, and the action is a walk of the tree. Often, an operation might be performed when a pointer arrives at a particular node. A walk in which each parent node is traversed before its children is called a pre-order walk; a walk in which the children are traversed before their respective parents are traversed is called a post-order walk.

Common operations

  • Enumerating all the items
  • Enumerating a section of a tree
  • Searching for an item
  • Adding a new item at a certain position on the tree
  • Deleting an item
  • Removing a whole section of a tree (called pruning
    Pruning (algorithm)

    Pruning is a term in mathematics and informatics which describes a method of enumeration, which allows to cut parts of a decision tree. Pruned parts of the tree are no longer considered because the algorithm knows based on already collected data that these subtrees do not contain the searched object....
    )
  • Adding a whole section to a tree (called grafting
    Grafting (algorithm)

    In computer science, grafting is a method used to manipulate trees. One such tree is an ordered tree, which is where the subtrees for any node are ordered....
    )
  • Finding the root for any node


Common uses

  • Manipulate hierarchical data
  • Make information easy to search
    Search algorithm

    In computer science, a search algorithm, broadly speaking, is an algorithm that takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions....
     (see tree traversal
    Tree traversal

    In computer science, tree-traversal refers to the process of visiting each node in a tree data structure, exactly once, in a systematic way. Such traversals are classified by the order in which the nodes are visited....
    )
  • Manipulate sorted lists
    Sorting algorithm

    In computer science and mathematics, a sorting algorithm is an algorithm that puts elements of a List in a certain Total order. The most-used orders are numerical order and lexicographical order....
     of data
  • As a workflow for compositing
    Digital compositing

    Digital compositing is the process of digitally assembling multiple images to make a final image, typically for print, film or screen display. It is the evolution into the digital realm of optical film compositing....
     digital images for visual effects
    Visual effects

    Visual effects are the various processes by which imagery is created and/or manipulated outside the context of a live action shoot. Visual effects often involve the integration of live-action footage and computer generated imagery in order to create environments which look realistic, but would be dangerous, costly, or simply impossible to...


See also

  • Binary space partitioning
    Binary space partitioning

    Binary space partitioning is a method for recursively subdividing a Euclidean space into convex sets by hyperplanes. This subdivision gives rise to a representation of the scene by means of a Tree known as a BSP tree....
  • Heap
    Heap (data structure)

    In computer science, a heap is a specialized tree data structure-based data structure that satisfies the heap property: if B is a child node of A, then key ≥ key....
  • Tree (graph theory)
    Tree (graph theory)

    In mathematics, more specifically graph theory, a tree is a graph in which any two Vertex are connected by exactly one path . Alternatively, any connectedness graph with no Cycle is a tree....
  • Tree (set theory)
    Tree (set theory)

    In set theory, a tree is a partially ordered set such that for each t ? T, the set is well-ordered by the relation <. For each t ? T, the order type of is called the height of t ....
  • Tree structure
    Tree structure

    A tree structure is a way of representing the hierarchy nature of a structure in a graphical form.It is named a "tree structure" because the graph looks a bit like a tree, even though the tree is generally shown upside down compared with a real tree; that is to say with the root at the top and the leaves at the bottom....
  • Trie
    Trie

    In computer science, a trie, or prefix tree, is an ordered tree data structure data structure that is used to store an associative array where the keys are usually string s....
  • Exponential tree
    Exponential tree

    An exponential tree is almost identical to a binary search tree, with the exception that the dimension of the tree is not the same at all levels....


Popular tree data structures


  • Binary Tree
    Binary tree

    In computer science, a binary tree is a Tree in which each node has at most two child node. Typically the child nodes are called left and right....


Self balancing binary search trees
Self-balancing binary search trees:
Self-balancing binary search tree

In computer science, a self-balancing binary search tree or height-balanced binary search tree is a binary search tree that attempts to keep its height, or the number of levels of nodes beneath the root, as small as possible at all times, automatically....
  • AA tree
    AA tree

    An AA tree in computer science is a form of Self-balancing binary search tree used for storing and retrieving ordered data efficiently. AA trees are named for Arne Andersson , their inventor....
  • AVL tree
    AVL tree

    In computer science, an AVL tree is a self-balancing binary search tree, and it is the first such data structure to be invented. In an AVL tree, the tree height of the two child node subtrees of any node differ by at most one; therefore, it is also said to be height-balanced tree....
  • Red-black tree
    Red-black tree

    A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science, typically used to implement associative arrays....
  • Splay tree
    Splay tree

    A splay tree is a self-balancing binary search tree with the additional property that recently accessed elements are quick to access again. It performs basic operations such as insertion, look-up and removal in big O notation amortized analysis time....
  • Scapegoat tree
    Scapegoat tree

    In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Igal Galperin and Ronald L. Rivest. It provides worst-case big O notation lookup time, and O amortized analysis insertion and deletion time....


Other trees
  • B-tree
    B-tree

    In computer science, a B-tree is a tree data structure that keeps data sorted and allows searches, insertions, and deletions in logarithmic Amortized analysis....
     (2-3 tree
    2-3 tree

    A 2-3 tree in computer science is a type of data structure, a B-tree where every Node with children has either two children and one data element or three children and two data elements ....
    , B+ tree
    B+ tree

    In computer science, a B+ tree is a type of tree data structure which represents sorted data in a way that allows for efficient insertion, retrieval and removal of records, each of which is identified by a key....
    , B*-tree
    B*-tree

    A B*-tree is a tree data structure, a variety of B-tree used in the Hierarchical File System and Reiser4 file systems, which requires non-root nodes to be at least 2/3 full instead of 1/2....
    , UB-tree
    UB-tree

    The UB-tree as proposed by Rudolf Bayer and Volker Markl is a balanced tree for storing and efficiently retrieving multidimensional data. It is basically a B+ tree with records stored according to Z-order , also called Morton order....
    )
  • DSW algorithm
    DSW algorithm

    The DSW algorithm, or in full Day/Stout/Warren algorithm, is a method for efficiently balancing binary search trees — that is, decreasing their height to Big-O notation nodes, where n is the total number of nodes....
  • Dancing tree
    Dancing tree

    In computer science, a dancing tree is a tree data structure. Invented by Hans Reiser, it is used by the Reiser4 file system. As opposed to self-balancing binary search trees that attempt to keep their nodes balanced at all times, dancing trees only balance their nodes when flushing data to a disk ....
  • Enfilade
    Enfilade (Xanadu)

    Enfilades are a class of Tree used in Project Xanadu designs of the 1970s and 1980s. Enfilades allow quick editing, versioning, retrieval and inter-comparison operations in a large, cross-linked hypertext database....
  • Fusion tree
    Fusion tree

    A fusion tree is a tree data structure that implements an associative array with integer keys up to a fixed size; by exploiting the constant-time machine word multiplication operation available on many real processors, it is able to achieve all operations in...
  • kd-tree
    Kd-tree

    In computer science, a kd-tree is a space partitioning data structure for organizing Point s in a k-dimensional Euclidean space. kd-trees are a useful data structure for several applications, such as searches involving a multidimensional search key ....
  • Octree
    Octree

    An octree is a tree data structure in which each internal node has up to eight children. Octrees are most often used to partition a three dimensional space by recursively subdividing it into eight octants....
  • Quadtree
    Quadtree

    A quadtree is a tree data structure in which each internal node has up to four children. Quadtrees are most often used to partition a two dimensional space by recursively subdividing it into four quadrants or regions....
  • R-tree
    R-tree

    R-trees are tree data structures that are similar to B-trees, but are used for spatial indexs i.e., for indexing multi-dimensional information; for example, the coordinates of geographical data....
  • Radix tree
    Radix tree

    A radix tree, Patricia trie/tree, or crit bit tree is a specialized set data structure based on the trie that is used to store a set of strings....
  • Segment tree
    Segment tree

    In computer science, a segment tree is a Tree data structure for storing Interval , or segments. It allows querying which of the stored segments contain a given point....
  • Skip list
    Skip list

    A skip list is a probabilistic data structure, based on multiple parallel, sorted linked lists, with algorithmic efficiency comparable to a binary search tree ....
  • T-tree
    T-tree

    In computer science a T-tree is a type of binary treedata structure that is used by main memory database, such asDataBlitz, Extremedb, MySQL Cluster, TimesTen and and by some operating system kernels...
  • T-pyramid
    T-pyramid

    A T-pyramid is a Tree in which every internal Node has 4 child-nodes.The arcs of the tree need not be recorded because the nodes can be stored in depth-first traversal order as with a heap ....
  • Top Trees
    Top Trees

    The Top Tree is a binary tree based data structure for unrooted dynamic Tree which is used mainly for carrying out various path related operations, it allows simple Divide and conquer algorithms....
  • Van Emde Boas tree
    Van Emde Boas tree

    A van Emde Boas tree , also known as a vEB tree, is a tree data structure which implements an associative array with m-bit integer keys....


External links

from the Dictionary of Algorithms and Data Structures
Dictionary of Algorithms and Data Structures

The Dictionary of Algorithms and Data Structures is a dictionary style reference for many algorithms, "algorithmic techniques", "archetypal problems" and data structures found in the field of Computer Science....
— opensource library