首页 > 其他分享 >图与树(CS)

图与树(CS)

时间:2023-08-16 23:44:25浏览次数:27  
标签:cur int graph push CS called

好长时间没更新博客了……最近确实发生了不少事情,导致更新不了
It's been a long time to not update my blog……Recently actually many things happen, so that I could have time to draw something.

Graph and Tree(CS)

图与树(CS)

Graph theory(Math)

图论(数学)

The paper written by Leonhard Euler on the Seven Bridges of Königsberg and published in 1736 is regarded as the first paper in the history of graph theory.
莱昂哈德·欧拉于1736年发表的关于柯尼斯堡七桥的论文被认为是图论史上的第一篇论文。
A graph (sometimes called an undirected graph to distinguish it from a directed graph, or a simple graph to distinguish it from a multigraph) is a pair \(G = (V, E)\), where \(V\) is a set whose elements are called vertices (singular: vertex), and E is a set of paired vertices, whose elements are called edges (sometimes links or lines).
一个图(有时称为无向图以将其与有向图区分开来,或称为简单图以将它与多重图区分开来)是一对\(G=(V,E)\),其中\(V\)是一个集合,其元素称为顶点(单数:顶点),E是一组成对的顶点,其元素也称为边(有时为链接或线)。
\(V\), a set of vertices (also called nodes or points);
\(E\subseteq \{\{x,y\}\mid x,y\in V\;{\textrm {and}}\;x\neq y\}\), a set of edges (also called links or lines), which are unordered pairs of vertices (that is, an edge is associated with two distinct vertices).

Breadth-First Search BFS

广度优先搜索

queue<int> q;
bool visited[N];
int dist[N];

void bfs(int x)
{
    visited[x] = true;
    q.push(x);
    dist[x] = 0;
    while (!q.empty())
    {
        int s = q.front();
        q.pop();
        for (auto &i : adj[s])
        {
            if (visited[i]) continue;
            visited[i] = true;
            // i, s
            dist[i] = dist[s] + 1;
            q.push(i);
        }
    }
}

Binary Tree(Recursion, CS in Math)

二叉树(Recursion, CS in Math)

在数学中是一种无向无环图(不是DAG)。必须递归定义。
A type of undirected acyclic graph in Math(not DAG). Must be defined by recursion.
(非空)二叉树是元组\((L,S,R)\),其中\(L\)和\(R\)是二叉树或空集,\(S\)是包含根的单例集。
A (nonempty) binary tree is a tuple $(L, S, R) $, where $L $and $R $are binary trees or empty sets, and $S $is a singleton containing roots.

Defining the binary tree as triplet \((V, E1, E2)\), where \((V, E1 ∪ E2)\) is a rooted tree.
\(E_1\subseteq \{\{x,y\}\mid x,y\in V\;{\textrm {and}}\;x\neq y\}\)
\(E_2\subseteq \{\{x,y\}\mid x,y\in V\;{\textrm {and}}\;x\neq y\}\)
\(E_1 ∩ E_2 = \emptyset\)
and also requiring that for all \(j ∈ { 1, 2 }\) every node has at most one \(E_j\) child.
This definition is not very strict.

Sequence traversal of binary trees

二叉树的层序遍历

    vector<vector<int>> levelOrder(TreeNode *root)
    {
        vector<vector<int>> res;
        if (!root)
            return res;

        queue<TreeNode *> q;
        q.push(root);

        while (!q.empty())
        {
            int sz = q.size();
            vector<int> level;
            for (int i = 0; i < sz; ++i)
            {
                TreeNode *cur = q.front();
                q.pop();
                level.push_back(cur->val);
                if (cur->left)
                    q.push(cur->left);
                if (cur->right)
                    q.push(cur->right);
            }
            res.push_back(level);
        }
        return res;
  }

标签:cur,int,graph,push,CS,called
From: https://www.cnblogs.com/qianxinn/p/17636502.html

相关文章

  • elasticsearch中的数据类型search_as_you_type及查看底层Lucene索引
    search_as_you_type字段类型用于自动补全,当用户输入搜索关键词的时候,还没输完就可以提示用户相关内容。as_you_type应该是说当你打字的时候。它会给索引里的这个类型的字段添加一些子字段_2gram_3gram和_index_prefix。_2gram的意思是,如果一个值是abcd,2gram就是abbccd,3gr......
  • 原生CSS嵌套简介
    嵌套是使用Sass等CSS预处理器的核心原因之一。现在,该功能已经以类似的语法出现在标准浏览器CSS中。你能否在构建系统时放弃对预处理器的依赖?CSS嵌套可以节省输入时间,并使语法更易于阅读和维护。迄今为止,你必须像这样键入完整的选择器路径:.parent1.child1,.parent2.child1{......
  • SkyEye操作指南:连接TI CCS的IDE调试
    现代电力电子控制系统的开发中,DSP芯片以其优越的运算性能在控制算法领域得到越来越广泛的应用。传统的DSP开发过程往往需要在完成控制系统仿真与程序设计后,才能根据比对结果进行程序修改,全过程还需要硬件电路工程师的配合,开发效率低下,灵活性差。为了快速验证控制算法,使仿真与开发......
  • CSP模拟22
    火批专场。骨架、灌伤、虚化、闪光只为碎银几两看世人慌慌张张只为碎银几两偏偏这碎银几两能解万种惆怅世人啊匆匆忙忙徒为碎银几两奈何这碎银几两让人心神荡漾A.骨架考虑点的贡献异常麻烦,我们可以把点的贡献转化为边的贡献。对于一条边,我们有如下几点:伴随着......
  • 将博客搬至CSDN
    鉴于博客园目前存在的危机,保险起见,将自己的文章搬到CSDN上CSDN: https://blog.csdn.net/qq_39529180博客园:https://www.cnblogs.com/strive-sun/......
  • 【快应用】快应用接入Analytics后自动采集事件LAUNCHAPP参数unknown?
    【关键词】快应用、接入Analytics、LAUNCHAPP、华为分析【问题背景】有cp反馈,快应用接入Analytics打开调试后,在“应用调试”界面“应用启动”事件$LaunchApp里面的$StartType和$StartSence参数取值都是unknown是什么原因?问题截图如下:【问题分析】$LaunchApp对应自动采集事件LAUN......
  • 中电金信通过KCSP认证 云原生能力获权威认可
    ​中电金信通过KCSP(KubernetesCertifiedServiceProvider)认证,正式成为CNCF(云原生计算基金会)官方认证的Kubernetes服务提供商。 ​ Kubernetes是容器管理编排引擎,底层实现为容器技术,是云原生领域最关键技术之一。作为全球最大的云计算社区——CNCF的第一个毕业项目,Kub......
  • Linux:修改系统时间,从EDT到CST
    学习自:修改linux系统的时间EDT为CST_51CTO博客_linux修改时区为cstEDT:美国东部夏令时间,波士顿、纽约市、华盛顿哥伦比亚特区,都在这个时区内,跟北京时间有12小时的时差,晚12小时。CST:美国中部标准时间(西六区,-6:00),中国是东八区(+8:00),北京时间比美国中部标准时间早14个小时。3:45P......
  • Docs命令之 ping的使用
    一、ping基本使用详解在网络中ping是一个十分强大的TCP/IP工具。它的作用主要为:1、用来检测网络的连通情况和分析网络速度2、根据域名得到服务器IP3、根据ping返回的TTL值来判断对方所使用的操作系统及数据包经过路由器数量。我们通常会用它来直接pingip地址,来......
  • CSP模拟21
    CSP模拟21T1GetP5999把跳的顺序转换为填数。对于一个位置,两边填的数都要小于或都大于它才符合题意。我们按照从小到大的顺序插入数字,这样保证填的位置左右都小于它。设\(dp_{i,j}\)表示填了\(i\)个数,分成了\(j\)个块的方案数。考虑添加一个数,我们有三种情况。\(i\)......