Binary Tree All Paths, Max Sum Path, Diameter, Longest Path, Shortest Path, Closest Leaf

Given a Binary Tree T.
1. Find all paths from root to each of the leaves in T.
2. Find the longest path from root to a leaf (also called Max Depth or Height of the tree).
3. Find the path that has largest sum along the path in T.
4. Find distance (shortest) between given two nodes in T.
5. Diameter of T or Longest path between any two nodes in T.
6. Find mirror image tree of T.
7. Find min length path that sums to a given value.
8. Find the closest leaf from root.

Binary Search Tree (BST) insert, delete, successor, predecessor, traversal, unique trees

From wiki, A binary search tree is a rooted binary tree, whose internal nodes each store a key (and optionally, an associated value) and each have two distinguished sub-trees, commonly denoted left and right. The tree additionally satisfies the binary search tree property, which states that the key in each node must be greater than all keys stored in the left sub-tree, and smaller than all keys in right sub-tree.[1] (The leaves (final nodes) of the tree contain no key and have no structure to distinguish them from one another. Leaves are commonly represented by a special leaf or nil symbol, a NULL pointer, etc.)

Find the rightmost cousin of a binary tree

Given a node in a binary tree. Find the rightmost cousin of the give node.

Let’s start with an example.

                             1
                          /      \
                         2        3
                      /         /   \
                     4         5     6
                       \           /
                        7         8

Rightmost cousin of 4 is 6, right most cousin of 7 is 8 and so on.