Rooted tree impossible constructs -
for uva problem, working on constructing rooted tree following constraints.
a tree of depth d means tree should contain @ least 1 node d distance away root , there no node of more d distance root.
the degree of node of tree cannot greater v . degree of node measured number of nodes directly connected to, via single edge.
the goal determine maximum possible number of nodes. find that, looking sum on v^i , ranges 0 d. summation appears give maximum number of nodes correctly in many cases, i'm assuming it's correct.
however, question states 'if not possible construct tree, print -1'. can think of no possible case might occur. think supposed be printed when user enters v , d outside range given in problem.
maximum number of nodes = 1 + ( v * ((v-1)^(d-1)) ) , v>=2, d>=1
.
explanation: 1 root node, 1st level can have v nodes, 2nd level on wards can have v-1 nodes, restrict maximum degree v.
it not possible construct tree if:
case 1: d=1 , v<1
case 2: d>1 , v<2
Comments
Post a Comment