Interview Question
- 0of 0 votes
AnswersYou are given the Ancestor matrix of a Binary tree, write an C program/function to construct the corresponding tree.
- Poornima April 28, 2015 in United States
For example, the below tree:
10
/ \
5 30
/ \ \
4 8 40
/
1
Will have the following ancestor Matrix
1 4 5 8 10 30 40
1 0 1 1 0 1 0 0
4 0 0 1 0 1 0 0
5 0 0 0 0 1 0 0
8 0 0 1 0 1 0 0
10 0 0 0 0 0 0 0
30 0 0 0 0 1 0 0
40 0 0 0 0 1 1 0
Essentially, in the ancestor matrix, each node has a row and a column (may not be the same). The value at a[i][j] will be 1 iff node of Node representing j‘th column is the ancestor of node representing the i‘th row.
Write an C program/function that can construct the binary tree from a given Ancestor matrix(2 dimensional array as input to the function).| Report Duplicate | Flag | PURGE
Java
Here the code for Ancestor Matrix in C#
- Ashish April 28, 2015