W Trees

The Tree Abstract Data Type (ADT)

(Heavily from https://www.geeksforgeeks.org/dsa/introduction-to-tree-data-structure/)

A tree is a hierarchical data structure that consists of nodes connected by edges. It is used to represent relationships between elements, where each node may hold data. Trees as a data structure organize and represent data in a parent–child relationship.

A tree consists of nodes such that there is a single topmost node called the root, and every other node can have one or more child nodes.

Each node may point to none or some other nodes. Unlike linked lists, where each node points to the next one and possibly to the previous one too (except for its two end nodes), nodes in a tree data structure store references to multiple child nodes, that is zero to any number.


Data in a tree is not stored sequentially (i.e., not in a linear order). Instead, it is organized across multiple levels, forming a hierarchical structure. Because of this arrangement, a tree is classified as a non-linear data structure.


Trees are useful for storing data that naturally forms a hierarchy. They help in efficient data organization and retrieval for hierarchical relationships.

Some examples:

Tree Terminology

Basic terms in the tree data structure:

Types of Tree Data Structures

Tree data structures can be classified based on the number of children each node can have.

Binary Trees

Each node can have a maximum of two children.

Some subtypes of binary tree:

  • Binary Search Tree (BST) and its Variations: each node has at most two children, and for each node, the left child<s value is smaller than the node<s value, and the right child<s value is greater.
  • Full Binary Tree: every node has either 0 or 2 children.
  • Complete Binary Tree: all levels are fully filled except possibly the last, which is filled from left to right.
  • Balanced Binary Tree: height difference between left and right subtrees of every node is minimal.

Some examples of Balanced Binary Tree are AVL Tree, Red Black Tree and Splay Tree.

Ternary Trees

Each node can have at most three children, often labeled as left, middle, and right.

N-ary Tree (or Generic Tree)

  • Each node can have any number of children.
  • Each node typically contains some data and a list of references to its children (duplicates are not allowed)

Some common subtypes of n-ary trees are:

  • B-tree: A self-balancing search tree where nodes can have multiple children, usually used for indexing large databases.
  • B+ Tree: a variation of the B-tree that only stores data in the leaf nodes, making range queries more efficient.
  • Trie (or Prefix Tree): A tree where each node represents a character, and paths from the root to leaves represent strings. It can have a variable number of children for each node, making it an N-ary tree.

Properties of Tree Data Structure

Forests*