Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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