We are given a binary search tree; we need to find out its border.
So, if the binary tree is
10
/ \
50 150
/ \ / \
25 75 200 20
/ \ / / \
15 35 120 155 250
It should print out 50 25 15 35 120 155 250 20 150 10
.
If the binary tree is
10
/ \
50 150
/ \ /
25 75 200
/ \ / \
15 35 65 30
It should be like 50 25 15 35 65 30 200 150 10
.
How can this be done? Does generalising this for a binary tree make the problem any harder?
Any help through links will also be appreciated.
P.S.: please see that the pattern does not start from root but from the left (in this case). It might also start with right, but it always ends with the root.