## Lab Test 1

### Part 1 [Maximum marks: 30]

A binary tree is supplied in the data file against your name. Read the file, and create the tree in the standard pointer-based repreentation. Maintain links for left and right chlidren. Don't maintain parent links. In the first line of the file, the number of nodes is supplied. If this number is n, nodes in the tree are identified as 0,1,2,...,n - 1. For each node, its ID and the IDs of its two child nodes are supplied in the file (-1 indicates no child, that is, NULL). While creating the tree, you also need to identify the root of the tree (it is not the node with ID 0). Return a pointer to the root node. In all of the subsequent parts, this pointer should be passed as the tree, not the raw data from the file.

Hint: After you read n from the input file, allocate a dynamic array of n tree nodes. Then, read the input file, and create child connections. The unique node which is not the child of any other node is the root node. However, if you are more comfortable with the conventional recursive way of creating the binary tree, store the data from the file in some array(s).

### Part 2 [Maximum marks: 30]

Print all the leaves of the tree.

### Part 3 [Maximum marks: 20]

Students with odd PC numbers: Determine the maximum level in the tree at which a leaf appears.

Students with even PC numbers: Determine the minimum level in the tree at which a leaf appears.

The root is assumed to be at level zero, its children at level 1, and so on.

### Part 4 [Maximum marks: 20]

Students with odd PC numbers: Print all the leaf nodes at the maximum level.

Students with even PC numbers: Print all the leaf nodes at the minimum level.

### Submission site

You must submit your C/C++ source file, and the output of your program on your input file given below.