Tree/bottom_top_view_binary_tree library
🌳 Bottom View and Top View of Binary Tree
Returns the bottom view and top view of a binary tree as lists of node values.
Time complexity: O(n) Space complexity: O(n)
Example:
final root = BinaryTreeNode<int>(20);
root.left = BinaryTreeNode<int>(8);
root.right = BinaryTreeNode<int>(22);
root.left!.left = BinaryTreeNode<int>(5);
root.left!.right = BinaryTreeNode<int>(3);
root.right!.left = BinaryTreeNode<int>(4);
root.right!.right = BinaryTreeNode<int>(25);
final bottom = bottomView(root);
final top = topView(root);
// bottom: [5, 8, 4, 22, 25]
// top: [5, 8, 20, 22, 25]
Functions
-
bottomView<
T> (BinaryTreeNode< T> ? root) → List<T> -
topView<
T> (BinaryTreeNode< T> ? root) → List<T>