How to create a binary tree with edges between nodes will given at run-time


  • 0
    L

    First line contains an interger N which is the number of nodes in the tree.
    Next N lines contain an integer each which are values associated with nodes i.e, ith line contains the value associated with node i-1.
    Next N-1 lines give the information of edges in the tree. Each line contains two Space separated integers X and Y which says that there is an edge between node X and node Y.

    If the following input is given, Can anyone give the code to create binary tree

    5
    0
    0
    1
    1
    1
    0 1
    0 2
    2 3
    2 4


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.