作业1 无向图的定义
Definition :An undirected network is a tuple N = ( V , E , W ) N = (V, \mathbf{E}, \mathbf{W}) N=(V,E,W),where V V V is the set of nodes, E ⊆ V × V \mathbf{E} \subseteq V \times V E⊆V×V where ( v i , v j ) ∈ E ⇔ ( v j , v i ) ∈ E (v_i,v_j) \in \mathbf{E} \Leftrightarrow (v_j,v_i) \in \mathbf{E} (vi,vj)∈E⇔(vj,vi)∈E is the set of nodes, w ∈ W w \in \mathbf{W} w∈W is the weighted of ( v i , v j ) (v_i, v_j) (vi,vj).
作业2 树的定义
(1)自己画一棵树, 将其元组各部分写出来 (特别是函数
p
p
p).
Let
ϕ
\phi
ϕ be the empty node, a tree is a triple
T
=
(
A
,
A
0
,
p
)
T=(\mathbf{A}, A_0, p)
T=(A,A0,p) where
∙
A
=
{
A
0
,
A
1
,
…
,
A
6
}
≠
ϕ
\bull \mathbf{A} =\{A_0, A_1, \dots, A_6\}\neq\phi
∙A={A0,A1,…,A6}=ϕ is the set of nodes;
∙
A
0
∈
A
\bull A_0\in \mathbf{A}
∙A0∈A is the root node;
∙
p
:
A
→
A
∪
{
ϕ
}
\bull p: \mathbf{A} \to\mathbf{A} \cup\{\phi\}
∙p:A→A∪{ϕ} is the parent mapping satisfying;
:
p
(
A
0
)
=
ϕ
:p(A_0)=\phi
:p(A0)=ϕ
:
∀
A
∈
A
,
∃
1
n
≥
0
,
st.
p
(
n
)
(
A
)
=
A
0
:\forall A \in \mathbf{A}, \exists 1 n \geq 0, \text { st. } p^{(n)}(A)=A_0
:∀A∈A,∃1n≥0, st. p(n)(A)=A0
(2)针对该树, 将代码中的变量值写出来
code:
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; // -1 即 \phi
}// Of the constructor
}//Of class Tree
其中:
n=6;root=0;
parent[0]=-1; parent[1]=0; parent[2]=0; parent[3]=1; parent[4]=1; parent[5]=2; parent[6]=2;
作业3
(1)画一棵三叉树, 并写出它的 child 数组
child:
{
(
1
,
2
,
3
)
;
(
4
,
−
1
,
5
)
;
(
−
1
,
−
1
,
6
)
;
(
−
1
,
−
1
,
−
1
)
;
(
−
1
,
−
1
,
−
1
)
;
(
−
1
,
−
1
,
−
1
)
;
(
−
1
,
−
1
,
−
1
)
}
\{(1, 2, 3) ;(4, -1, 5) ;(-1, -1, 6) ;(-1, -1,-1) ;(-1,-1,-1) ;(-1,-1,-1) ;(-1,-1,-1)\}
{(1,2,3);(4,−1,5);(−1,−1,6);(−1,−1,−1);(−1,−1,−1);(−1,−1,−1);(−1,−1,−1)}
(2)重新定义树
Let
ϕ
\phi
ϕ be the empty node, a tree is a triple
T
=
(
A
,
A
0
,
Σ
,
c
)
T=(\mathbf{A}, A_0, \Sigma, c)
T=(A,A0,Σ,c) where
∙
A
=
{
A
0
,
A
1
,
…
,
A
6
}
≠
ϕ
\bull \mathbf{A} =\{A_0, A_1, \dots, A_6\}\neq\phi
∙A={A0,A1,…,A6}=ϕ is the set of nodes;
∙
A
0
∈
A
\bull A_0\in \mathbf{A}
∙A0∈A is the root node;
∙
Σ
=
{
0
,
…
,
6
}
\bull \Sigma =\{0,\dots,6\}
∙Σ={0,…,6} is the alphabet;
∙
c
:
(
A
∪
{
ϕ
}
)
×
Σ
∗
→
A
∪
{
ϕ
}
\bull c:(\mathbf{A} \cup\{\phi\}) \times \Sigma^{*} \rightarrow \mathbf{A} \cup\{\phi\}
∙c:(A∪{ϕ})×Σ∗→A∪{ϕ} satisfying ;
∙
∀
A
∈
A
,
∃
1
s
∈
Σ
∗
st.
c
(
r
,
s
)
=
A
\bull \forall A \in \mathbf{A}, \exists 1 s \in \Sigma^{*} \text { st. } c(r, s)=A
∙∀A∈A,∃1s∈Σ∗ st. c(r,s)=A