Tree/print_all_root_to_leaf_paths library

🌳 Print All Root-to-Leaf Paths in a Binary Tree

Returns all paths from the root to each leaf node as lists of values.

Time complexity: O(n) Space complexity: O(h) for recursion, plus O(n) for storing paths

Example:

final root = BinaryTreeNode<int>(1);
root.left = BinaryTreeNode<int>(2);
root.right = BinaryTreeNode<int>(3);
root.left!.left = BinaryTreeNode<int>(4);
root.left!.right = BinaryTreeNode<int>(5);
final paths = printAllRootToLeafPaths(root);
// paths: [[1,2,4],[1,2,5],[1,3]]

Functions

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