Tree/morris_traversal library

🌳 Morris Traversal (Inorder Traversal without Stack or Recursion)

Efficiently traverses a binary tree in inorder sequence using O(1) space. This algorithm temporarily modifies the tree structure (threading) and restores it after traversal.

Time complexity: O(n) Space complexity: O(1)

Example:

final root = BinaryTreeNode<int>(10);
root.left = BinaryTreeNode<int>(5);
root.right = BinaryTreeNode<int>(15);
final result = morrisInorderTraversal(root);
// result: [5, 10, 15]

Functions

morrisInorderTraversal<T>(BinaryTreeNode<T>? root) → List<T>