[Math] Postorder and Preorder traversal on a Binary tree

trees

For the tree below, list the labels of the nodes of the tree according to the pre-ordering algorithm, and then re-list them according to the post-ordering algorithm.

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

Is my attempt correct I always get confused between the traversal methods:

Pre-ordering: 1, 2, 4, 7, 5, 8, 3, 6, 9, 10

Post-ordering: 7, 8, 4, 5, 2, 9, 10, 6, 3

Best Answer

Looks good; you just made a couple errors. The pre-order traversal should be: $$ 1, 2, 4, 7, \color{red}8, \color{red}5, 3, 6, 9, 10 $$ and the post-order should finish at the root, $1$.

Related Question