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 :-
Construct a tree, given its inorder and preorder traversals.

Solution :-
Suppose the inorder array is { 4 , 2 , 5 , 1 , 6 , 3 } and the
preorder array is { 1 , 2 , 4 , 5 , 3 , 6 }
We will pick up the first element 1 from preorder array and search that element in the inorder array .
1 becomes the root element and all elements on the left of 1 in the inorder array i.e { 4 , 2 , 5 } forms the left subtree and elements on the right { 6 , 3 } forms the right subtree of 1. Then we look for second element 2 in the preorder array and recursively construct the subtrees of that element. This process is repeated till the entire preorder array is traversed and the complete tree is constructed. Following figure demonstrates the procedure.