元组:类似于java的对象,是一系列基本数据结构(集合,向量,关系)的复合数据结构。
- 定义无向网络
- Definition1.1 An undirected net is a tuple G = ( V , w ) G=(\mathrm{V},w) G=(V,w) , where V \mathrm{V} V is the set of nodes, and w : V × V → R w:\mathrm{V} \times \mathrm{V} \rightarrow \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 edge ( v i , v j ) ( v_i, v_j ) (vi,vj), ∀ v i , v j ∈ V , w ( v i , v j ) = w ( v j , v i ) \forall v_i,v_j\in\mathbf{V}, w(v_i, v_j) = w(v_j,v_i) ∀vi,vj∈V,w(vi,vj)=w(vj,vi).
- 自己画一棵树, 将其元组各部分写出来 (特别是函数 p p p)
- Let
ϕ
\phi
ϕ be the empty node, a tree is a triple
T
=
(
V
,
r
,
p
)
\mathrm{T}=(\mathbf{V}, r, p)
T=(V,r,p) where
a) V = { 1 , 2 , 3 , 4 , 6 , 7 , 8 } ≠ ∅ \mathbf{V}=\{1, 2, 3, 4, 6, 7, 8\}\neq\emptyset V={1,2,3,4,6,7,8}=∅;
b) r = 8 ∈ V r=8\in\mathbf{V} r=8∈V is the root node;
c) p : V ∪ { ϕ } → V ∪ { ϕ } p:\mathbf{V} \cup \{\phi\}\to\mathbf{V}\cup\{\phi\} p:V∪{ϕ}→V∪{ϕ} is the parent mapping satifying- p ( r ) = ϕ p(r) = \phi p(r)=ϕ;
- ∀ v ∈ V , ∃ ! n ≥ 0 , s.t. p n ( v ) = r \forall v \in \mathbf{V }, \exists ! n \geq 0, \textrm{s.t. }p^n(v)=r ∀v∈V,∃!n≥0,s.t. pn(v)=r
比如: p ( 1 ) = 2 ; p ( 2 ) = 4 ; p 2 ( 1 ) = p ( p ( 1 ) ) = p ( 2 ) = 4 p(1) = 2; p(2) = 4; p^2(1) = p(p(1)) = p(2) = 4 p(1)=2;p(2)=4;p2(1)=p(p(1))=p(2)=4
- 针对该树, 将代码中的变量值写出来 (特别是 parent 数组)
public class Tree {
/**
* 节点集合,顺序无关
*/
private int[] nodes;
/**
* 根节点. 处于nodes数组的index位置
*/
private int rootIndex;
/**
* 父节点.,第parent[i]存储nodes[i]的父节点为nodes[parent[i]]
*/
private int[] parent;
public Tree(int[] nodes, int rootIndex, int[] parent) {
this.nodes = nodes;
this.rootIndex = rootIndex;
this.parent = parent;
}
/**
* 获取值在nodes的index(位置)
* @param value
* @return
*/
public int getIndex(int value){
for (int i = 0; i < nodes.length; i++) {
if (value == nodes[i]){
return i;
}
}
//没有 返回-1
return -1;
}
public static void main(String[] args) {
int[] nodes = {1, 2, 3, 4, 6, 7, 8};
int rootoIndex = 6;
//-1 表示为空节点
int[] parent = {1, 3, 1, 6, 3, 3, -1};
Tree tree = new Tree(nodes, rootoIndex, parent);
//p^2(1) = 4, 1节点的index为0
//True
System.out.println(tree.getIndex(4) == tree.parent[(tree.parent[tree.getIndex(1)])]);
}
}//Of class Tree
- 修改了原有的n,使得元素排列可以乱序;
- getIndex(int value)方法 获取value在nodes数组的位置(0开始);
- tree.parent[(tree.parent[tree.getIndex(1)])]) 和表达式 p 2 ( 1 ) = 4 p^2(1) = 4 p2(1)=4惊人的相似;
- 画一棵三叉树, 并写出它的 child 数组
[ 1 2 3 4 5 − 1 − 1 − 1 − 1 − 1 − 1 − 1 6 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 ] \begin{bmatrix}1 & 2 & 3\\ 4 & 5 & -1 \\ -1 & -1 & -1 \\ -1 & -1 & -1 \\ 6 & -1 & -1 \\ -1 & -1 & -1 \\ -1 & -1 & -1 \\ \end{bmatrix} ⎣⎢⎢⎢⎢⎢⎢⎢⎢⎡14−1−16−1−125−1−1−1−1−13−1−1−1−1−1−1⎦⎥⎥⎥⎥⎥⎥⎥⎥⎤
- 可以看到叶子节点对应的行都是-1,表示读入任意状态后都为空节点
- 按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素
用自动机的形式定义树
Definition:let ϕ \phi ϕ be the empty node, a tree is a quadruple B T = ( V , r , Σ , p ) \mathrm{BT} = (\mathbf{V}, r, \Sigma, p) BT=(V,r,Σ,p) where - V \mathbf{V} V is the set of nodes;
- r ∈ V r \in \mathbf{V} r∈V is the root node;
- Σ = { p } \Sigma = \{\textrm{p}\} Σ={p} is the alphabet;
-
p
:
V
×
Σ
∗
→
V
∪
{
ϕ
}
p:\mathbf{V} \times \Sigma^{*}\to \mathbf{V} \cup \{\phi\}
p:V×Σ∗→V∪{ϕ} satisfying
- ∀ v ∈ V , ∃ ! s ∈ Σ ∗ , s.t. p ( v , s ) = r \forall v\in \mathbf{V}, \exists ! s \in \Sigma^{*}, \textrm{s.t. } p(v,s) = r ∀v∈V,∃!s∈Σ∗,s.t. p(v,s)=r
- 根据图、树、m-叉树的学习, 谈谈你对元组的理解
图对应着多对多的数据结构,树对应着一对多的数据结构,m-叉树是特殊的树,其中的子树有顺序,且不能为空树
而现实生活中诸多的应用场景都是复杂的,上述单一的数据结构并不能满足我们的需求,需要复合的使用,这个就是对应了元组,语义上解释:元数据结构组合使用。 - 找一篇你们小组的论文来详细分析数学表达式, 包括其涵义, 规范, 优点和缺点.
对于这样的复合的表达式,先从内到外理解。比如说对于表达式5
max a ∈ A min b ∈ B ∥ a − b ∥ \max_{a\in\mathrm{A}}\min_{b \in \mathrm{B}}\|a-b\| a∈Amaxb∈Bmin∥a−b∥
这样的写法类似于双重循环,外部max是首层循环,内部的min是内层循环
max b ∈ B min a ∈ A ∥ b − a ∥ \max_{b\in\mathrm{B}}\min_{a \in \mathrm{A}}\|b-a\| b∈Bmaxa∈Amin∥b−a∥
相同的,这个只是调转了 A , B \mathrm{A},\mathrm{B} A,B
疑问:
- ∥ . ∥ \|.\| ∥.∥对于这样的表述是不是有歧义,这个符号表示范数,但是没有带具体的下标,不知道是什么范数,在原文中表述为计算欧式距离(Euclidean distance),那应该算是二范数,但是并没有表述为 ∥ . ∥ 2 \|.\|_2 ∥.∥2这样的形式。