Tree (data structure)
Tree (data structure)
A tree is a widely used abstract data type (ADT) that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes. A tree data structure is a collection of nodes connected by edges, where each node contains a value or data and may have a reference to other nodes, known as its children.
Structure[edit | edit source]
A tree consists of nodes and edges. The topmost node is called the root, and each node (except the root) is connected by a single edge to exactly one other node, which is its parent. A node that has no children is called a leaf node. Nodes that have the same parent are called siblings.
Types of Trees[edit | edit source]
There are several types of trees, each with its own properties and applications:
- Binary tree: A tree in which each node has at most two children, referred to as the left child and the right child.
- Binary search tree (BST): A binary tree in which the left subtree of a node contains only nodes with values less than the node's value, and the right subtree only nodes with values greater than the node's value.
- AVL tree: A self-balancing binary search tree where the difference in heights between the left and right subtrees cannot be more than one for all nodes.
- Red-black tree: A self-balancing binary search tree where each node contains an extra bit for denoting the color of the node, either red or black.
- B-tree: A self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time.
- Trie: A tree-like data structure that stores a dynamic set of strings, where the keys are usually strings.
Operations[edit | edit source]
Common operations on a tree data structure include:
- Insertion: Adding a node to the tree.
- Deletion: Removing a node from the tree.
- Traversal: Visiting all the nodes in a specific order. Common traversal methods include pre-order traversal, in-order traversal, and post-order traversal.
- Searching: Finding a node in the tree that contains a specific value.
Applications[edit | edit source]
Trees are used in various applications, including:
- File systems: Organizing files and directories.
- Databases: Implementing indexes for efficient data retrieval.
- Network routing: Representing hierarchical network structures.
- Artificial intelligence: Representing decision processes in algorithms like decision trees.
Related Pages[edit | edit source]
See Also[edit | edit source]
Search WikiMD
Ad.Tired of being Overweight? Try W8MD's physician weight loss program.
Semaglutide (Ozempic / Wegovy and Tirzepatide (Mounjaro / Zepbound) available.
Advertise on WikiMD
WikiMD's Wellness Encyclopedia |
Let Food Be Thy Medicine Medicine Thy Food - Hippocrates |
Translate this page: - East Asian
中文,
日本,
한국어,
South Asian
हिन्दी,
தமிழ்,
తెలుగు,
Urdu,
ಕನ್ನಡ,
Southeast Asian
Indonesian,
Vietnamese,
Thai,
မြန်မာဘာသာ,
বাংলা
European
español,
Deutsch,
français,
Greek,
português do Brasil,
polski,
română,
русский,
Nederlands,
norsk,
svenska,
suomi,
Italian
Middle Eastern & African
عربى,
Turkish,
Persian,
Hebrew,
Afrikaans,
isiZulu,
Kiswahili,
Other
Bulgarian,
Hungarian,
Czech,
Swedish,
മലയാളം,
मराठी,
ਪੰਜਾਬੀ,
ગુજરાતી,
Portuguese,
Ukrainian
WikiMD is not a substitute for professional medical advice. See full disclaimer.
Credits:Most images are courtesy of Wikimedia commons, and templates Wikipedia, licensed under CC BY SA or similar.
Contributors: Prab R. Tumpati, MD