Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the problem code in C + + & run it . Problem: Given a tree of n ( 1 < = n < =

Write the problem code in C++ & run it. Problem: Given a tree of n (1<= n <=1000) nodes labelled from 0 to n -1,
and an array of n -1 edges where an edge {a, b} indicates that
there is an undirected edge between the two nodes a and b in
the tree. Note that any node of the tree can act as a root.
The height of a rooted tree is the number of edges on the
longest path between the root and a leaf. When you select a
node x as the root, the resultant tree has height h(x). Among all
possible rooted trees, those with the minimum height are
called minimum height trees (MHTs). Print the roots of
all MHTs. Constraints:
1<= n <=20000
0<= a, b < n
a != b
All the pairs {a, b} are distinct.
The given input is guaranteed to be a tree.
Input: n =4
{1,0},{1,2},{1,3}
Output: {1}
Input: n =6
{3,0},{3,1},{3,2},{3,4},{5,4}
Output: {3,4}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions