Given a binary tree, traverse the tree nodes layer by layer in order of

advertisement
Tree Question List:
1. Binary Tree traversal, Non-Recursive Pre-Order/In-Order/PostOrder (DFS)
Given a binary tree, traverse the tree nodes in pre-order/in-order/post-order, iteratively.
2. Binary Tree Traversal (Threading), layer by layer (BFS)
Given a binary tree, traverse the tree nodes layer by layer in order of, left-to-right, right-to-left,
and ZigZag.
Problem 3.10 of “Programming Beauty”
3. Lowest Ancestor of Binary Tree
Given a binary tree, find the lowest common ancestor of two given nodes in the tree.
http://www.leetcode.com/2011/07/lowest-common-ancestor-of-a-binary-tree-part-i.html
4. Construct Binary Tree from Pre-order/In-order/Post-order
Given pre-order/in-order/post-order traversal of binary tree nodes, construct the binary tree.
A different version of the problem would be to serialize a binary tree to transmit over the
Internet.
http://www.leetcode.com/2011/04/construct-binary-tree-from-inorder-and-preorderpostorder-traversal.html
5. Largest Binary Search Tree in a Binary Tree
Given a binary tree, find the largest Binary Search Tree (BST), where largest means BST with
largest number of nodes in it. The largest BST may or may not include all of its descendants.
http://www.leetcode.com/2010/11/largest-binary-search-tree-bst-in_22.html
6. Longest Distance of two nodes of a Binary tree
Define “Distance” of two nodes as the number of edges between these two nodes. Find the
largest distance between the nodes in the tree.
Problem 3.8 of “Programming Beauty”
7. DFS (Pre-Order/In-Order/Post-Order) threading a given binary tree
8. Mirror/Duplicate/Demolition a given (binary) tree
9. Comparison between two given (binary) trees
10.
Flatten a binary tree
11.
Reverse a tree
12.
Serialize a binary tree so it can be read/write from the file
13.
Convert a sorted array to balanced BST (Balancing BST)
http://www.leetcode.com/2010/11/convert-sorted-array-into-balanced.html
14.
Convert BST to sorted doubly linked-list or sorted array
http://www.leetcode.com/2010/11/convert-binary-search-tree-bst-to.html
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers
as synonymous to the previous and next pointers in a doubly-linked list.
15.
Print Edge Nodes (Boundary) of a Binary Tree
Print all edge nodes of a complete binary tree anti-clockwise. That is all the left most nodes
starting at root, then the leaves left to right and finally all the rightmost nodes. In other words,
print the boundary of the tree. Variant: Print the same for a tree that is not complete.
http://www.leetcode.com/2010/10/print-edge-nodes-boundary-of-binary.html
16. A binary tree problem – Populating next right pointers in each
node
Given a binary tree
struct Node {
Node* leftChild;
Node* rightChild;
Node* nextRight;
}
Populate the nextRight pointers in each node. You may assume that it is a full binary tree (ie,
each node other than the leaves has two children.)
http://www.leetcode.com/2010/03/first-on-site-technical-interview.html
17.
Print BST traversal path (GOOG)
Given a BST and two nodes' value on the tree, print the "UP", "LEFT" or "RIGHT" from S to T:



If it goes up, print "UP"
If it goes down to left child, print "LEFT"
If it goes down to right child, print "RIGHT"
18.
Deep Copy binary tree
Deep copy a binary tree, each tree node has three filed, left, right and random. The Random
points to any valid tree node.
Download