Tree/boundary_traversal library

🌳 Boundary Traversal of Binary Tree

Returns the boundary nodes of a binary tree in anti-clockwise order: root, left boundary, leaves, right boundary (bottom-up).

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

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);
root.right!.left = BinaryTreeNode<int>(6);
root.right!.right = BinaryTreeNode<int>(7);
final result = boundaryTraversal(root);
// result: [1,2,4,5,6,7,3]

Functions

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