Tree/vertical_order_traversal library

🌳 Vertical Order Traversal of Binary Tree

Returns a list of lists, each containing the nodes at the same vertical column. Columns are ordered from leftmost to rightmost.

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

Example:

final root = BinaryTreeNode<int>(3);
root.left = BinaryTreeNode<int>(9);
root.right = BinaryTreeNode<int>(8);
root.left!.left = BinaryTreeNode<int>(4);
root.left!.right = BinaryTreeNode<int>(0);
root.right!.left = BinaryTreeNode<int>(1);
root.right!.right = BinaryTreeNode<int>(7);
final result = verticalOrderTraversal(root);
// result: [[4], [9], [3,0,1], [8], [7]]

Functions

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