Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Tree Data Structures and Algorithms Cheat Sheet

Tree Data Structures and Algorithms Cheat Sheet

Back to Mathematics and Algorithms
Updated 2026-05-19
Next Topic: Trigonometry Cheat Sheet

Trees are the foundation of hierarchical data organization in computer science β€” from database indexes (B-trees, Red-Black trees) to file systems, compilers, and network routing. Unlike linear structures, trees enable O(log n) search, insertion, and deletion when balanced, and support complex queries over hierarchical data. This cheat sheet covers every major tree structure and algorithm, from fundamental BST operations through advanced techniques like Heavy-Light Decomposition, Centroid Decomposition, and persistent segment trees used in competitive programming and production systems.

What This Cheat Sheet Covers

This topic spans 15 focused tables and 122 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Binary Search Tree (BST) β€” Core Properties and OperationsTable 2: AVL Trees β€” Self-Balancing via RotationsTable 3: Red-Black Trees β€” Production Self-Balancing BSTTable 4: Segment Trees β€” Range Queries and UpdatesTable 5: Fenwick Trees (Binary Indexed Trees) β€” Prefix Sum StructuresTable 6: Trie (Prefix Tree) β€” String IndexingTable 7: Tree Traversal MethodsTable 8: Lowest Common Ancestor (LCA)Table 9: Tree DP β€” Dynamic Programming on TreesTable 10: Euler Tour Technique β€” Subtree as Array RangeTable 11: Heavy-Light Decomposition (HLD)Table 12: Centroid DecompositionTable 13: Tree Diameter and Related Path ProblemsTable 14: Treap and Splay Trees β€” Randomized and Self-Adjusting BSTsTable 15: Sparse Table β€” O(1) Range Minimum / Maximum Query

Table 1: Binary Search Tree (BST) β€” Core Properties and Operations

The BST is the starting point for all search trees: a binary tree where every left-subtree key is smaller than the node and every right-subtree key is larger. Understanding its fundamental operations β€” and its worst-case degeneration β€” motivates every balanced-tree variant that follows.

StructureExampleDescription
BST Property
left.key < node.key < right.key
Every node satisfies: all keys in left subtree < node key < all keys in right subtree; enables O(log n) search on balanced trees.
Search
if key < node: go left
elif key > node: go right
else: found
Compare key with node; recurse left or right; O(log n) balanced, O(n) worst case (degenerate/linked-list tree).
Insertion
BST.insert(5) β†’ walk to null leaf, place node
Search for key until null leaf; insert new node there; O(log n) average, O(n) worst.
Deletion
delete node with 2 children β†’ replace with inorder successor
β€’ 0 children: remove directly
β€’ 1 child: replace node with child
β€’ 2 children: replace with inorder successor (smallest in right subtree), then delete successor
Inorder Traversal
inorder(BST) β†’ [1, 3, 5, 7, 9]
Visiting nodes left β†’ root β†’ right yields keys in sorted ascending order β€” a unique BST property.
Floor / Ceiling
floor(6) on {1,3,5,7} β†’ 5
ceil(6) β†’ 7
Floor: largest key ≀ query. Ceiling: smallest key β‰₯ query. Both O(log n) via BST traversal.

More in Mathematics and Algorithms

  • Topology Cheat Sheet
  • Trigonometry Cheat Sheet
  • Algebra Cheat Sheet
  • Combinatorics Cheat Sheet
  • Geometry Cheat Sheet
  • Mathematical Proof Techniques Cheat Sheet
View all 37 topics in Mathematics and Algorithms