数学表达式——第四天

本文介绍了树和无向网络的数学定义,以元组形式展示,强调了它们在数据结构中的重要性。通过一个树的例子展示了如何用代码实现,包括节点集合、根节点和父节点映射。此外,还提出了四元组的自动机形式定义树,进一步探讨了树的结构。文章最后讨论了复合数据结构在信息技术中的应用,并以数学表达式为例阐述了其解析过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

元组:类似于java的对象,是一系列基本数据结构(集合,向量,关系)的复合数据结构。

  1. 定义无向网络
  • 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→Rw:\mathrm{V} \times \mathrm{V} \rightarrow \mathbb{R}w:V×VR is the weight function where w(vi,vj)w(v_i, v_j)w(vi,vj) is the weight of the edge(vi,vj)( v_i, v_j )(vi,vj), ∀vi,vj∈V,w(vi,vj)=w(vj,vi)\forall v_i,v_j\in\mathbf{V}, w(v_i, v_j) = w(v_j,v_i)vi,vjV,w(vi,vj)=w(vj,vi).
  1. 自己画一棵树, 将其元组各部分写出来 (特别是函数 ppp)
  • 树
  • Let ϕ\phiϕ be the empty node, a tree is a tripleT=(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\emptysetV={1,2,3,4,6,7,8}=;
    b) r=8∈Vr=8\in\mathbf{V}r=8V 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
    1. p(r)=ϕp(r) = \phip(r)=ϕ;
    2. ∀v∈V,∃!n≥0,s.t. pn(v)=r\forall v \in \mathbf{V }, \exists ! n \geq 0, \textrm{s.t. }p^n(v)=rvV,!n0,s.t. pn(v)=r

比如:p(1)=2;p(2)=4;p2(1)=p(p(1))=p(2)=4p(1) = 2; p(2) = 4; p^2(1) = p(p(1)) = p(2) = 4p(1)=2;p(2)=4;p2(1)=p(p(1))=p(2)=4

  1. 针对该树, 将代码中的变量值写出来 (特别是 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)])]) 和表达式p2(1)=4p^2(1) = 4p2(1)=4惊人的相似;
  1. 画一棵三叉树, 并写出它的 child 数组
    三叉树

[12345−1−1−1−1−1−1−16−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}141161125111113111111

  • 可以看到叶子节点对应的行都是-1,表示读入任意状态后都为空节点
  • 按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素
    用自动机的形式定义树
    Definition:let ϕ\phiϕ be the empty node, a tree is a quadruple BT=(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∈Vr \in \mathbf{V}rV 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) = rvV,!sΣ,s.t. p(v,s)=r
  1. 根据图、树、m-叉树的学习, 谈谈你对元组的理解
    图对应着多对多的数据结构,树对应着一对多的数据结构,m-叉树是特殊的树,其中的子树有顺序,且不能为空树
    而现实生活中诸多的应用场景都是复杂的,上述单一的数据结构并不能满足我们的需求,需要复合的使用,这个就是对应了元组,语义上解释:元数据结构组合使用。
  2. 找一篇你们小组的论文来详细分析数学表达式, 包括其涵义, 规范, 优点和缺点.
    数学表达式

对于这样的复合的表达式,先从内到外理解。比如说对于表达式5

max⁡a∈Amin⁡b∈B∥a−b∥\max_{a\in\mathrm{A}}\min_{b \in \mathrm{B}}\|a-b\|aAmaxbBminab

这样的写法类似于双重循环,外部max是首层循环,内部的min是内层循环

max⁡b∈Bmin⁡a∈A∥b−a∥\max_{b\in\mathrm{B}}\min_{a \in \mathrm{A}}\|b-a\|bBmaxaAminba

相同的,这个只是调转了A,B\mathrm{A},\mathrm{B}A,B

疑问:

  • ∥.∥\|.\|.对于这样的表述是不是有歧义,这个符号表示范数,但是没有带具体的下标,不知道是什么范数,在原文中表述为计算欧式距离(Euclidean distance),那应该算是二范数,但是并没有表述为∥.∥2\|.\|_2.2这样的形式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来日可期1314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值