:
In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, a ternary tree is a
tree data structure
In computer science, a tree is a widely used abstract data type that represents a hierarchical tree structure with a set of connected nodes. Each node in the tree can be connected to many children (depending on the type of tree), but must be conn ...
in which each node has at most three child
nodes
In general, a node is a localized swelling (a "knot") or a point of intersection (a Vertex (graph theory), vertex).
Node may refer to:
In mathematics
*Vertex (graph theory), a vertex in a mathematical graph
*Vertex (geometry), a point where two ...
, usually distinguished as "left", “mid” and "right". Nodes with children are parent nodes, and child nodes may contain references to their parents. Outside the tree, there is often a reference to the "root" node (the ancestor of all nodes), if it exists. Any node in the data structure can be reached by starting at root node and repeatedly following references to either the left, mid or right child.
Ternary trees are used to implement
Ternary search tree
In computer science, a ternary search tree is a type of trie (sometimes called a ''prefix tree'') where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two. Lik ...
s and
Ternary heap
Ternary (from Latin ''ternarius'') or trinary is an adjective meaning "composed of three items". It can refer to:
Mathematics and logic
* Ternary numeral system, a base-3 counting system
** Balanced ternary, a positional numeral system, useful ...
s.
Definition
* Directed Edge - The link from the parent to the child.
* Root - The node with no parents. There is at most one root node in a rooted tree.
* Leaf Node - Any node that has no children.
* Parent Node - Any node connected by a directed edge to its child or children.
* Child Node - Any node connected to a parent node by a directed edge.
* Depth - Length of the path from the root to the node. The set of all nodes at a given depth is sometimes called a level of the tree. The root node is at depth zero.
* Height - Length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero. In the example diagram, the tree has height of 2.
* Sibling - Nodes that share the same parent node.
- A node p is an ancestor of a node q if it exists on the path from q to the root. The node q is then termed a descendant of p.
- A size of a node is the number of descendants it has including itself.
Properties of ternary trees
* Maximum number of nodes
– Let
be height of a ternary tree.
– Let
be the maximum number of nodes in a ternary tree of height h
–
– Every tree of height h has at most
nodes.
* If a node
occupies TREE