11. 图与网络
作业:
- 写出该无向图的邻接矩阵.
[ 0 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 ] \left[\begin{array}{llll}0 & 1 & 1 & 1\\ 1 & 0 & 1 & 0\\ 1 & 1 & 0 & 1\\ 1 & 0 & 1 & 0 \end{array}\right] ⎣⎢⎢⎡0111101011011010⎦⎥⎥⎤
- 定义无向网络
A undirected net is a tuple G = ( V , w ) G = (\mathbf{V}, w) G=(V,w), where V \mathbf{V} V is the set of nodes, and w : V × V → R w: \mathbf{V} \times \mathbf{V} \to \mathbb{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 j , v i ) w(v_j, v_i) w(vj,vi) is the weight of the arc ⟨ v j , v i ⟩ \langle v_j, v_i \rangle ⟨vj,vi⟩.
12. 树
作业:
- 自己画一棵树, 将其元组各部分写出来 (特别是函数 p pp).
This tree is a triple
T
=
(
V
,
r
,
p
)
T = (\mathbf{V}, r, p)
T=(V,r,p);
V
=
{
v
0
,
v
1
,
v
2
,
v
3
,
v
4
}
V = \{v0, v1, v2, v3, v4\}
V={v0,v1,v2,v3,v4};
r
=
v
0
r = v0
r=v0;
p
(
v
3
)
=
p
(
v
4
)
=
v
1
,
p
(
v
1
)
=
p
(
v
2
)
=
v
0
,
p
(
v
0
)
=
ϕ
p(v3) = p(v4) = v1, p(v1) = p(v2) = v0, p(v0) = \phi
p(v3)=p(v4)=v1,p(v1)=p(v2)=v0,p(v0)=ϕ
- 针对该树, 将代码中的变量值写出来 (特别是 parent 数组).
public class Tree {
/**
* 节点数. 表示节点 v_0 至 v_{n-1}.
*/
int n;
/**
* 根节点. 0 至 n-1.
*/
int root;
/**
* 父节点.
*/
int[] parent;
/**
* 构造一棵树, 第一个节点为根节点, 其余节点均为其直接子节点, 也均为叶节点.
*/
public Tree(int paraN) {
n = paraN;
parent = new int[n];
parent[0] = -1; // 即 \phi
}// Of the constructor
}//Of class Tree
n = 6;
root = 0;
parent = [0, 1, 2, 3, 4, -1]
13. m 叉树
作业:
- 画一棵三叉树, 并写出它的 child 数组.
[
1
2
3
4
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
−
1
]
\left[\begin{array}{llll}1 & 2 & 3 \\ 4 & -1 & -1\\ -1 & -1 & -1\\ -1 & -1 & -1\\-1 & -1 & -1 \end{array}\right]
⎣⎢⎢⎢⎢⎡14−1−1−12−1−1−1−13−1−1−1−1⎦⎥⎥⎥⎥⎤
- 按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素.
A tree is a 5-tuple T = ( Σ , V ′ , r , ϕ , p ) T = (\Sigma, \bm{V'}, \bm{r}, \bm{\phi}, p) T=(Σ,V′,r,ϕ,p), where
- Σ \Sigma Σ is the alphabet, Σ = { k } \Sigma= \{k\} Σ={k} ;
- V ′ \bm{V'} V′ is the set of states, V ′ = V ∪ { ϕ } \bm{V'}=\bm{V} \cup \{\phi\} V′=V∪{ϕ}, V = { v 1 , … , v n } \mathbf{V} = \{v_1, \dots, v_n\} V={v1,…,vn} ;
- r ∈ V ′ r \in \bm{V'} r∈V′ is the root;
- ϕ ∈ V ′ \phi \in \bm{V'} ϕ∈V′ is the terminal states;
- p : V ′ × Σ ∗ → V ′ p: \bm{V'}\times \Sigma^* \to \bm{V'} p:V′×Σ∗→V′ is the transition function, satisfying ∀ v ∈ V \forall v \in \bm{V} ∀v∈V, ∃ 1 \exists 1 ∃1 s ∈ Σ ∗ s \in \Sigma^* s∈Σ∗ st. c ( v , s ) = r c(v, s) = r c(v,s)=r.
- 根据图、树、m mm-叉树的学习, 谈谈你对元组的理解.
我认为元组就是将对象的几个属性集合起来对对象进行描述。