DEV Community

Cover image for Data Structures and Algorithms: Trees
Farai Bvuma
Farai Bvuma

Posted on

2

Data Structures and Algorithms: Trees

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

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay