Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ex. 2.8 Trees Let T be an arbitrary tree where each vertex v in T has a field v.numb. Present an algorithm that for each
Ex. 2.8 Trees Let T be an arbitrary tree where each vertex v in T has a field v.numb. Present an algorithm that for each y in T, stores in v.numb the number of leaves the subtree rooted by v. If v is a leaf, this number should be one. Suggestion: use pseudocode such as: if v is a leaf then Ex. 2.9 Trees Let T be an arbitrary tree where each vertex v in T' has a field v.dis. Present an algorithm that for each v in T, stores in v.dis the distance (ie., number of edges) from v to the most distant leaf in the subtree rooted by v. If v is a leaf, this distance should be zero. Ex. 2.10 Trees Let T be an arbitrary tree where each vertex v in T has the fields v.1dis and v.2dis. Present an algorithm that for each v in T, stores in v.1dis the distance (i.e., number of edges) from v to the most distant leaf in the subtree rooted by v. If v is a leaf, this distance should be zero. Suppose the path from y to this most distant leaf goes from through the vertex z that is a child of v and then continues down the subtree rooted by z to the leaf. The value for v.dis2 is the distance to the most distant leaf that is in the subtree rooted by v but not in the subtree rooted by the 2. You can think of this v.dis2 and the associated leaf as a backup in case z gets sick and has to go home. If v has just one child, then v.dis2 should be -oo Ex. 2.8 Trees Let T be an arbitrary tree where each vertex v in T has a field v.numb. Present an algorithm that for each y in T, stores in v.numb the number of leaves the subtree rooted by v. If v is a leaf, this number should be one. Suggestion: use pseudocode such as: if v is a leaf then Ex. 2.9 Trees Let T be an arbitrary tree where each vertex v in T' has a field v.dis. Present an algorithm that for each v in T, stores in v.dis the distance (ie., number of edges) from v to the most distant leaf in the subtree rooted by v. If v is a leaf, this distance should be zero. Ex. 2.10 Trees Let T be an arbitrary tree where each vertex v in T has the fields v.1dis and v.2dis. Present an algorithm that for each v in T, stores in v.1dis the distance (i.e., number of edges) from v to the most distant leaf in the subtree rooted by v. If v is a leaf, this distance should be zero. Suppose the path from y to this most distant leaf goes from through the vertex z that is a child of v and then continues down the subtree rooted by z to the leaf. The value for v.dis2 is the distance to the most distant leaf that is in the subtree rooted by v but not in the subtree rooted by the 2. You can think of this v.dis2 and the associated leaf as a backup in case z gets sick and has to go home. If v has just one child, then v.dis2 should be -oo
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started