闵老板帖子:数学表达式魔训
Q1.写出该无向图的邻接矩阵.
邻接矩阵表示为:
$$\mathbf{E} = \begin{bmatrix} 0& 1& 1& 1 \\ 1 &0 &1 &0 \\ 1 &1 & 0& 1 \\1 &0 &1 & 0 \end{bmatrix}$$
Q2.定义无向网络.
Definition: An undirected net is a tuple \(G =(\mathbf{V}, w)\), where \(\mathbf{V}\) is the set of nodes, and \(w:\mathbf{V} \times \mathbf{V} \to \mathbb{R}\) is the weight function where \(w(v_i, v_j)\) is the weight of the edge \((v_i, v_j)\), and \(w(v_i, v_j) = w(v_j, v_i)\).
Q3.自己画一棵树, 将其元组各部分写出来 (特别是函数\(p\)).
\(\mathbf{V} = \{v_0, v_1, v_2, v_3, v_4, v_5 \}\).
\( r = v_0 \).
\( p^0(v_0) = v_0, p(v_1) = v_0, p(v_2) = v_0, p(v_3) = v_0, p(v_4) = v_1, p^2(v_4) = v_0, p(v_5) = v_1, p^2(v_5) = v_0\).
Q4.针对该树, 将代码中的变量值写出来 (特别是 parent 数组).
n = 6;
root = 0;
parent = new int[6];
parent[0] = -1;
parent[4] = 1;
parent[5] = 1;
Q5.画一颗三叉树, 并写出它的child数组.
(二次使用.)
child数组表示为:\(\{ \{1, 2, 3\},\{ 4, 5, -1\}, \{-1, -1, -1\}, \{-1, -1, -1\} ,\{-1, -1, -1\}, \{-1, -1, -1\} \} \).
矩阵:
$$C = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & -1 \\ -1& -1 &-1 \\ -1& -1 &-1 \\ -1& -1 &-1 \\ -1& -1 &-1 \end{bmatrix}$$
Q6.按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素.
Definition: let \(\phi\) be the empty node, an \(m\)-tree is a quadruple \(T = \{\mathbf{V}, r, \Sigma, p\}\) where
a)\(\mathbf{V}\) is the set of nodes;
b)\( r \in \mathbf{V}\) is the root node;
c)\(\Sigma\) is the alphabet, and \(\Sigma = \{1\}\);
d)\(p : (\mathbf{V} \cup \{\phi\}) \times \Sigma^* \to \mathbf{V} \times \{\phi\}\) is the parent funciton satisfying
\(\forall v \in \mathbf{V}, \exists ! s \in \Sigma^*\) st.\(p(v, s) = r.\)
Q7.根据图、树、\(m\)-叉树的学习, 谈谈你对元组的理解.
元组不同于其他的“容器”, 它能将不同类型的对象存储到一起, 使得我们在图、树、\(m\)-叉树的定义中更加的简便.