Assignments 4 Tree
Assignments 4 Tree
Trees
1. Given a tree, your task is to write a program with following functions
● Calculate the height of the tree.
● Check if the given tree is a binary tree? If yes, write out the order of nodes in inorder
traversal.
Input: Data come from the keyboard:
- The first line contains integer numbers N, M indicating the number of nodes, and edges,
respectively.
- M following lines each contains two integer numbers u, v indicating that u is the parent of
v.
Output: Data are written to the screen as following:
- The height of the tree
- The order of nodes in preorder traversal
- The order of nodes in postorder traversal
- The order of nodes in the inorder if the tree is binary. Otherwise, write the string ‘NOT
BINARY TREE’
Keyboard Screen
54 2
12 12453
13 45231
24 4 2513
25