?
2010-12-01 09:18:50 UTC
/|\
/ | \
/ | \
B C D(D HAS 2 CHILDREN I AND J) ....Depth=2,level 2,first do bfs
/| |\ \\ Breadth=2,level 2,do dfs(right branch to left branch)
/ | | \ \\
/ | | \ \\
E F G H IJ(J HAS 1 CHILD O)
/ | / | | .......depth=3,level 3,first do bfs
/ | / | | breadth=3,level 3,do dfs(right to left)
K L M N O ....depth=4,level 4,first do bfs
/| breadth=4,level 4,do dfs(right to left)
/ |
/ |
P Q
the tree has total 17 nodes(A to Q)
the edges are A B,A C,A D,B E,B F,C G,C H,D I,D J,E K,E L,H M,H N,J O,L P,L Q.
Here,the dfs search will be carried out in the opposite of the normal convention i.e. from right to left.
The first level(level 1) will search as bfs/dfs(searching in this level won matter since the level has only 1 node A).Next in level 2,it will first search in bfs fashion and will print BCD,then it will search this level in dfs fashion and it will print JO.In the next level(level 3),same procedure will be followed,the level will be first searched in bfs manner and it will print EFGHI,then it will be searched in dfs manner and it will print NM.Same process will be followed in level 4 and it will print KL for bfs and PQ for dfs.It is to be noted that once one of the nodes are searched in bfs/dfs,they are not to be considered for the next level's search,like when in level 3,we get EFGHI whilesearching in bfs,but we dont consider J since it is already visited in the previous level's dfs search.
the program will print
A-BCD-JO-EFGHI-NM-KL-QP