Perfect Binary Tree Specific Level Order Traversal
PreviousConvert a given tree to its Sum TreeNextChange a Binary Tree so that every node stores sum of all nodes in left subtree
Last updated
Last updated
Given a Perfect Binary Tree like below: (click on image to get a clear view)
Print the level order of nodes in following specific manner:
1 2 3 4 7 5 6 8 15 9 14 10 13 11 12 16 31 17 30 18 29 19 28 20 27 21 26 22 25 23 24
i.e. print nodes in level order but nodes should be from left and right side alternatively. Here 1st and 2nd levels are trivial. While 3rd level: 4(left), 7(right), 5(left), 6(right) are printed. While 4th level: 8(left), 15(right), 9(left), 14(right), .. are printed. While 5th level: 16(left), 31(right), 17(left), 30(right), .. are printed.