Fiveable

๐Ÿ“ŠGraph Theory Unit 5 Review

QR code for Graph Theory practice questions

5.2 Rooted trees and binary trees

๐Ÿ“ŠGraph Theory
Unit 5 Review

5.2 Rooted trees and binary trees

Written by the Fiveable Content Team โ€ข Last updated September 2025
Written by the Fiveable Content Team โ€ข Last updated September 2025
๐Ÿ“ŠGraph Theory
Unit & Topic Study Guides

Tree structures are fundamental in graph theory, forming hierarchical relationships between nodes. Rooted trees establish a clear structure with a designated root, while binary trees limit nodes to two children. These structures enable efficient data organization and manipulation.

Tree traversal methods like preorder, inorder, and postorder allow systematic exploration of tree nodes. Binary tree properties find applications in various domains, including search algorithms, data compression, and machine learning, showcasing their versatility and importance in computer science.

Tree Structures and Components

Components of rooted trees

  • Rooted trees form connected acyclic graphs with designated root node establishing hierarchical structure through directed edges
  • Root node sits at top of tree hierarchy without parent node
  • Parent nodes connect directly to child nodes moving towards root
  • Child nodes connect directly to parent nodes moving away from root
  • Leaves (terminal nodes) have no children
  • Internal nodes exist between root and leaves with both parent and child nodes
  • Siblings share same parent node
  • Depth of node measures path length from root
  • Height of tree equals maximum depth of any node

Ordered vs unordered rooted trees

  • Ordered rooted trees maintain specific left-to-right order for children nodes (file systems)
  • Unordered rooted trees disregard sibling order (set representations)
  • Isomorphic ordered trees with different sibling arrangements considered distinct
  • Isomorphic unordered trees with different sibling arrangements considered equivalent

Binary trees and subtrees

  • Binary trees limit nodes to maximum two children designated as left and right
  • Full binary trees contain nodes with either 0 or 2 children
  • Complete binary trees fill all levels except possibly last from left to right
  • Perfect binary trees have all internal nodes with two children and leaves at same level
  • Balanced binary trees maintain height difference of at most one between left and right subtrees

Binary tree traversal methods

  • Preorder traversal: visit root, traverse left subtree, traverse right subtree (copying trees)
  • Inorder traversal: traverse left subtree, visit root, traverse right subtree (sorted order for binary search trees)
  • Postorder traversal: traverse left subtree, traverse right subtree, visit root (node deletion)
  • Implement traversals recursively or iteratively using stack

Applications of binary tree properties

  • Height analysis: $O(log n)$ for balanced trees, $O(n)$ for skewed trees
  • Node count in perfect binary tree: $2^{h+1} - 1$ where h is height
  • Array representation for complete binary trees, linked representation for general binary trees
  • Binary search trees enable $O(log n)$ average case search time
  • Tree balancing techniques (AVL trees, Red-Black trees) optimize performance
  • Expression trees facilitate arithmetic operations
  • Huffman coding enables data compression
  • Decision trees support machine learning algorithms