Data Structures & Algorithms
237 notes
Some notes are currently available only in Chinese. English translations are shown when available.
- Lowest Common Ancestor of a Binary Treehistorical
Given a binary tree, find the lowest common ancestor of two specified nodes in the tree.
- Mirror of a Binary Treehistorical
Transform a binary tree into its mirror by swapping the left and right subtrees at every node.
- Diameter of Binary Treehistorical
Given a binary tree, calculate its diameter. The diameter of a binary tree is the maximum path length between any two nodes. This path may or may not pass through the root.
- Print a Binary Tree in Multiple Lineshistorical
Print a binary tree level by level from top to bottom, with nodes on the same level output from left to right. Output each level on a separate line.
- Lowest Common Ancestor Nodehistorical
Given a binary tree and two nodes o1 and o2 in the tree, find their lowest common ancestor.
- Print a Binary Tree in Zigzag Orderhistorical
Implement a function that prints a binary tree in zigzag order: the first row from left to right, the second level from right to left, the third row from left to right, and so on.
- Merge Two Binary Treeshistorical
Merge two binary trees by adding the values of overlapping nodes and retaining nodes that do not overlap.
- Substructure of a Treehistorical
Given two binary trees A and B, determine whether B is a substructure of A. (ps: an empty tree is not considered a substructure of any tree.).