GeeksforGeeks » Interview Questions
converting n*n matrix representation of a binary tree to array representation
(1 post)-
We have give n*n matrix (having values as 1 or 0) which represents binary tree. if matrix[i][j] == 1 then j is parent of i we have to convert that matrix into array representation of tree
Array representation of tree means tree is stored in a array such that a[2*n] and a[2*n+1] are children of node n.
We have to convert n*n 2D matrix representation of tree to 1D matrix of size 2^n-1.
i/p
0 0 0 0 1
0 0 0 0 1
0 1 0 0 0
1 0 0 0 0
0 0 0 0 0o/p
[5, 1, 2, 4, 0, 3, 0, 0, 0... ]
Reply
You must log in to post.