The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

# Algorithms

## Tree

Problem :-
Compute the Diameter of a given Binary Tree.
Diameter of a tree is the largest path between any two leaf nodes in the tree.
For e.g, in the tree shown below diameter is 5 because the longest path ( { 29 , 24 , 16 , 31 , 52 } or
{ 19 , 24 , 16 , 31 , 52 } ) consists of 5 nodes.

Solution :-
Assume that root node is a part of the longest path between two leaf nodes. We need to compute the height of left subtree ( lh ) and the right subtree ( rh ) of root. Then, the diameter is lh + rh + 1. We will recursively consider other nodes of the tree as part of longest path and compute the diameters. Finally, we will return the maximum diameter. See the implementation below.