Question: 3 . 2 Let be the undirected binary tree ( see example in problem 3 . 1 ) . For each pair of vertices, we
Let
be the undirected binary tree see example in problem For each pair of vertices, we can compute the distance between these vertices. In figure in for example, we have
dist The diameter of T to be the maximum value of distxy chosen over all pairs of vertices x and y in T In Java,
a create an algorithm, BFSvertex G vertex s to compute the diameter of T points
Input for the tree build can be arrays that represent the edges, eg for figure in to to to to :
int V new int;
int N new int;
Then, to build a tree G use this:
int order ; example where max in V and N is
vertex G new vertexorder;
forint i ; i Glength; i
Gi new vertexi ;
forint i ; i Vlength; i
ifGVinghs
GVinghs Ni;
else ifGVinghs
GVinghs Ni;
And
public class vertex
final int key;
int color, d;
int nghs new int;
public vertexint k
key k;
color ;
d ;
nghs;
nghs;
b explain how your algorithm works points
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
