Data Structures and Algorithms: Trees
Farai Bvuma
Posted on April 26, 2024
Trees are a hierarchical data structure represented by nodes. Each node will have a value and possible children.
Terminology
Root - The first node in a tree.
Height - The length of the longest path from the root to the furthest child node.
Leaves - Nodes without children.
Binary Tree - A tree that has at most 2 children. Usually described as left or right.
General Tree - any tree with 0 or more children.
Binary Search Tree - a tree which has a specific ordering and at most 2 children nodes.
Balanced - a tree is considered to be balanced when the left and right children are of the same height.
Branching Factor - the amount of children that a tree has, for example, a binary tree has a branching factor of 2.
Traversal - The process by which each node in a tree is visited. The two main methods for tree traversal are Depth First Traversal and Breadth First Traversal.
Conclusion
The aim of this article was to serve as an introduction to trees. The next articles will go into detail about the types of tree traversal.
Posted on April 26, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.