作业Day4
作者:互联网
Q1:定义无向网络
Definition: An undirected net is a tuple G = ( V , w ) G=(\mathbf V,w) G=(V,w),where V \mathbf V Vis the set of nodes,and w : V × V → R w:\mathbf V\times \mathbf V\to\R w:V×V→R is the weight function where w ( v i , v j ) w(v_i,v_j) w(vi,vj) is the weight of the arc ⟨ v i , v j ⟩ \langle v_i,v_j\rangle ⟨vi,vj⟩ and w ( v i , v j ) = w ( v j , v i ) w(v_i,v_j)=w(v_j,v_i) w(vi,vj)=w(vj,vi), v i , v j ∈ V v_i,v_j\in\mathbf V vi,vj∈V
Q2.1:自己画一棵树, 将其元组各部分写出来
A tree is a triple
T
=
(
V
,
r
,
p
)
T = (\mathbf{V}, r, p)
T=(V,r,p)
In this tree,
V
=
{
a
,
b
,
c
,
d
,
e
,
f
,
g
}
,
r
=
a
\mathbf V=\{a,b,c,d,e,f,g\},r=a
V={a,b,c,d,e,f,g},r=a,
p
(
f
)
=
p
(
g
)
=
d
,
p
(
e
)
=
c
,
p
(
d
)
=
b
,
p
(
b
)
=
p
(
c
)
=
a
,
p
(
a
)
=
ϕ
p(f)=p(g)=d,p(e)=c,p(d)=b,p(b)=p(c)=a,p(a)=\phi
p(f)=p(g)=d,p(e)=c,p(d)=b,p(b)=p(c)=a,p(a)=ϕ
Q3:针对该树, 将代码中的变量值写出来 (特别是 parent 数组).
public class Tree {
//节点数. 表示节点 v_0 至 v_{n-1}.
int n;
//根节点. 0 至 n-1.
int root;
//父节点.
char[] parent;
/**
* 构造一棵树, 第一个节点为根节点, 其余节点均为其直接子节点, 也均为叶节点.
*/
public Tree(int paraN) {
n = paraN;
parent = new char[n];
parent[0] = -1; // -1 即 \phi
}// Of the constructor
}//Of class Tree
a: b:
n = 7 n=4
root = 'a' root = 'b'
parent = null parent =
???
标签:mathbf,parent,int,vi,Day4,作业,节点,vj 来源: https://blog.csdn.net/weixin_44569973/article/details/119322341