Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with part 3 and part 4 of question 3 3. Random Trees The nx.random_tree (n) command can be used to generate a random

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedneed help with part 3 and part 4 of question 3

3. Random Trees The nx.random_tree (n) command can be used to generate a random tree on the n vertices represented in python by range( n ) (in order). Such a tree can be converted into a sequence of n2 numbers, its Prfer code by the python function pruefer_code , defined as follows: Conversely, the following function tree_pruefer constructs a tree from a Prfer code. ]: def tree_pruefer(code): \# initialize graph and defects n= len(code) +2 tree = nx.empty_graph(n) degrees =[1 for x in tree] for y in code: degrees[y]+= 1 \# add edges for y in code: 9]:T2= tree_pruefer (code ) 1. Construct random trees on n=10,11,12 nodes (one each is enough). For each such tree, draw it, compute its Prfer code and then convert the code back into a tree. Do you get your old tree back? 1. Construct random trees on n=10,11,12 nodes (one each is enough). For each such tree, draw it, compute its Prfer code and then convert the code back into a tree. Do you get your old tree back? In [173]: \( \begin{array}{ll}T=\mathrm{nx} \cdot \text { random_tree }(11) \\ \mathrm{nx} \cdot \mathrm{draw}(\mathrm{T}, * * \text { opts) }\end{array} \) 7 \[ \begin{array}{l} {[177]: \begin{array}{l} \text { code }=\text { pruefer_code }(T) \\ \text { code } \end{array}} \\ \mathrm{t}[177]:[8,0,8,6,2,10,10,10,10] \end{array} \] Yes, the original tree and the tree constructed from the Prfer code are the same, as can be seen by comparing the draw outputs. 2. For a few randomly chosen Prfer codes, construct the corresponding tree, draw it if you want, and convert it back into a Prfer code. Do you get your old code back? code2 In [183]:code2=pruefercode(T5)code2 Out [183]:[3,0,0] In [184]:n=7code=np,randomrandint(n,size=n2)code In [186]:code2= pruefer_code (T7) code2 out [186]:[0,6,5,5,0] The output will show the original Prufer code, the reconstructed Prufer code and a boolean indicating if the two codes match. If the code and the reconstructed code match, then we have gotten the same tree back 3. Which labelled tree on n nodes {0,1,,n1} corresponds to the Prfer code [0,1,2,,n3] ? ... your comments here... 4. Which labelled tree on n nodes {0,1,,n1} corresponds to a Prfer code which has n2 identical entries

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

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Demonstrate through language that you are grateful to be informed.

Answered: 1 week ago

Question

Always mention the specifi c problem the customer faced.

Answered: 1 week ago