Share to: share facebook share twitter share wa share telegram print page

Tree (data structure)

An example of a tree.

In computer science, a tree is a graph data structure composed of items called nodes. These nodes can point to other nodes, known as child nodes, or children.[1] Usually, a tree is read from top to bottom.

Every tree has a node known as a root node. The root node does not have a node that points to it, but it can point to other nodes. In other words, no node has the root as a child.

The thing that makes trees different from a normal graph data structure is that trees may not have cycles. This means that between any two nodes, there can only exist one path between the nodes. If there was more than one path, the structure would just be a graph data structure.

A node is known as a leaf if it has no children. The bottom of a tree structure will usually be the place with the most leaves. The height of a node is the length of the longest path from a specific node to a leaf below that node.[2] The height of the root is also known as the height of a tree. The height of the root would be determined by the length of the longest path from the root of a tree to a leaf of that tree. [3] The depth of a node is the length of the path from the tree's root to that node.[4]

Example

  • The item labeled 2 in green text is the root.
  • The item labeled 4 is a leaf and its depth is 3.
  • The height of the tree is 3.

List of tree data structures

References

  1. "Introduction to Tree Data Structure - GeeksforGeeks". GeeksforGeeks. 2021-06-21. Retrieved 2025-08-24.
  2. "Height and Depth of a node in a Binary Tree". GeeksforGeeks. 2021-03-05. Retrieved 2025-08-24.
  3. "Introduction to Tree Data Structure - GeeksforGeeks". GeeksforGeeks. 2021-06-21. Retrieved 2025-08-24.
  4. "Introduction to Tree Data Structure - GeeksforGeeks". GeeksforGeeks. 2021-06-21. Retrieved 2025-08-24.
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya