Lecture 23: Graphs and Traversals | cs61b 2019

最短路径问题算法(Shortest Path Problems' Algorithms) 最短路径问题算法 作者:Bluemapleman(tomqianmaple@outlook.com) 麻烦不吝star和fork本博文对应的github上的技术博客项目吧!谢谢你们的支持! 知识无价,写作辛苦,欢迎转载,但请注明出处,谢谢! 文章目录最短路径问题算法单源最短路径问题设定引入Bellman-Ford算法DAG的单源最短路径算法Dijkstra算法(迪杰斯特拉算法)多源多目标最短路径... 阅读详情

Lecture 23: Graphs and Traversals

  • Tree Traversals
  • Graphs
  • Depth First Search
  • Breadth First Search

Trees and Traversals

Tree Definition

A tree consists of:

  • A set of nodes.
  • A set of edges that connect those nodes.
    • Constraint: There is exactly one path between any two nodes.
      在这里插入图片描述

Rooted Trees Definition

A rooted tree is a tree where we’ve chosen one node as the “root”.

  • Every node N except the root has exactly one parent, defined as the first node on the path from N to the root.
  • A node with no child is called a leaf.

Tree Traversal Orderings

Depth First Traversals
  • 3 types: Preorder, Inorder, Postorder
  • Basic (rough) idea: Traverse “deep nodes” (e.g. A) before shallow ones (e.g. F).
  • Note: Traversing a node is different than “visiting” a node. See next slide.
    在这里插入图片描述
Preorder: “Visit” a node, then traverse its children: D B A C F E G

在这里插入图片描述

Inorder traversal: Traverse left child, visit, then traverse right child: A B C D E F G
inOrder(BSTNode x) {
    if (x == null) return;
    inOrder(x.left)
    print(x.key)
    inOrder(x.right)
}
Postorder traversal: Traverse left, traverse right, then visit: ACBEGFD
postOrder(BSTNode x) {
    if (x == null) return;
    postOrder(x.left)
    postOrder(x.right)
    print(x.key)
}
A Useful Visual Trick (for Humans, Not Algorithms)

在这里插入图片描述

What Good Are All These Traversals?

Example 1:
在这里插入图片描述
Example 2:
在这里插入图片描述

Graphs

Graph Definition

A graph consists of:

  • A set of nodes.
  • A set of zero or more edges, each of which connects two nodes.

在这里插入图片描述
A simple graph is a graph with:

  • No edges that connect a vertex to itself, i.e. no “loops”.
  • No two edges that connect the same vertices, i.e. no “parallel edges”.
    在这里插入图片描述
    In 61B, unless otherwise explicitly stated, all graphs will be simple

Graph Types

在这里插入图片描述

Graph Terminology

在这里插入图片描述

Graph Problems

Graph Queries More Theoretically

Some well known graph problems and their common names:

  • s-t Path. Is there a path between vertices s and t?
  • Connectivity. Is the graph connected, i.e. is there a path between all vertices?
  • Biconnectivity. Is there a vertex whose removal disconnects the graph?
  • Shortest s-t Path. What is the shortest path between vertices s and t?
  • Cycle Detection. Does the graph contain any cycles?
  • Euler Tour. Is there a cycle that uses every edge exactly once?
  • Hamilton Tour. Is there a cycle that uses every vertex exactly once?
  • Planarity. Can you draw the graph on paper with no crossing edges?
  • Isomorphism. Are two graphs isomorphic (the same graph in disguise)?

Depth-First Traversal

s-t Connectivity solved by DFS

s-t connectivity problem
  • Given source vertex s and a target vertex t, is there a path between s and t?
  • Requires us to traverse the graph somehow.
    Try to come up with an algorithm for connected(s, t).

在这里插入图片描述

idea

One possible recursive algorithm for connected(s, t).

  • Mark s.
  • Does s == t? If so, return true.
  • Otherwise, if connected(v, t) for any unmarked neighbor v of s, return true.
  • Return false.

demo
在这里插入图片描述

Depth First Traversal

This idea of exploring a neighbor’s entire subgraph before moving on to the next neighbor is known as Depth First Traversal.

  • Example: Explore 1’s subgraph completely before using the edge 0-3.
  • Called “depth first” because you go as deep as possible.
    在这里插入图片描述

Another example:

  • Let’s discuss an algorithm that computes a path to every vertex.
  • Let’s call this algorithm DepthFirstPaths.
  • Demo: DepthFirstPaths.
    在这里插入图片描述

Tree Vs. Graph Traversals

DFS Preorder

What we just did in DepthFirstPaths is called “DFS Preorder

  • DFS Preorder: Action is before DFS calls to neighbors.
    • Our action was setting edgeTo.
    • Example: edgeTo[1] was set before DFS calls to neighbors 2 and 4.
  • One valid DFS preorder for this graph: 012543678
    • Equivalent to the order of dfs calls.

在这里插入图片描述

DFS Postorder.

DFS Postorder: Action is after DFS calls to neighbors.

  • Example: dfs(s):

    • mark(s)
    • For each unmarked neighbor n of s, dfs(n)
    • print(s)
  • Results for dfs(0) would be: 347685210

  • Equivalent to the order of dfs returns.(和DFS 执行完返回的顺序一致,即逆序)

在这里插入图片描述
在这里插入图片描述

Summary

Graphs are a more general idea than a tree.

  • A tree is a graph where there are no cycles and every vertex is connected.
  • Key graph terms: Directed, Undirected, Cyclic, Acyclic, Path, Cycle.

Graph problems vary widely in difficulty.

  • Common tool for solving almost all graph problems is traversal.
  • A traversal is an order in which you visit / act upon vertices.
  • Tree traversals:
    • Preorder, inorder, postorder, level order.
  • Graph traversals:
    • DFS preorder, DFS postorder, BFS.
    • By performing actions / setting instance variables during a graph (or tree) traversal, you can solve problems like s-t connectivity or path finding.
Baidu Apollo代码解析之s-t图的创建与采样(path_time_graph) 百度Apollo中使用Frenet坐标系下的s-t图来帮助分析障碍物的状态(静态、动态)对于自车轨迹规划的影响。典型的如Lattice Planner中,在s-t图中绘制出障碍物占据的s-t区间范围,便可以在范围外采样无碰撞的轨迹点(end condition),然后拟合和评估轨迹,选取最优的输出。 在s-t图中,静态障碍物是矩形块表示,因为直观的,随着时间推移,其s轴位置始终不变;动态障碍物是... 阅读详情

相关推荐

Berkeley CS61B Spring 2019 打卡(1)

仅供自勉和记录所用刷题记录在Dropbox Paper上2019 May 20 刷题记录在Dropbox Paper上 2019 May 20

weixin_41264869的博客 747

最短路径问题 Shortest Path

最短路径问题 Shortest Path

底层码农 7386

野火STM32F407(骄阳)+无刷直流驱动板+永磁同步电机控制学习记录(四)(基于HAL库)

以上内容都是参考别人资料自学的,很多地方都是凭感觉,因为理论部分不太会算,只要电机能转就行,其他性能指标都没考虑,因为不会,所以这纯属是学习记录帖。带宽在500时,电流波动小,但是响应很慢,就是堵转后不太容易恢复转动。速度环带宽设定小了,响应不够快,带宽设定大了波动比较大,电机感觉起来也震一点,而且,当带宽设到200的时候,启动直接就锁死了,应该是PI增益设定太大了。电流环带宽的试验:去掉速度环,让Iq_Set=2,Ud=0,此时电机是电流环闭环控制,用手堵转电机然后松开,看电流的波动以及响应情况。

XUEXIDEXIAOhai的博客 4572

Apollo_ADS_路径规划3- 速度曲线 优化_QP-Spline-ST-Speed Optimizer

QP-Spline-ST-Speed Optimizer ST纵向距离 VS 时间,station-time (S-T) S 纵向arc lengthVS Lateral 横向距离station-lateral https://github.com/ApolloAuto/apollo/blob/master/docs/specs/qp_spline_st_speed_optimizer...

chepwavege的专栏 5552

数据结构之栈(Stack)的实现详解

堆栈是一种线性数据结构,其插入新元素和删除现有元素都发生在堆栈的顶部。栈(Stack)按照"后进先出"(Last-In-First-Out,LIFO)的原则存储和访问数据。栈类似于现实生活中的堆叠物体,比如一摞书或者一堆盘子。

swadian2008的博客 3815

云计算学习——5G网络技术

华为eNSP网络设备模拟器的基础安装及简单使用

qq_42520799的博客 1449

CS61BSpring2019笔记1: 图的最短路径以及最小生成树

CS61B2019Spring笔记(1)问题描述ShortestPathTree三级目MinimumSpanningTree三级目算法证明Dijkstra三级目Prim三级目后续更新一些相关的leetcode题目 问题描述 ShortestPathTree 三级目 MinimumSpanningTree 三级目 算法证明 Dijkstra 三级目 Prim 三级目 后续更新一些相关的leetcode题目 ...

qq_41953962的博客 625

配置xen上VM混杂模式,使其能捕获物理网络流量

本文目的:配置VM和xen相应的物理网卡(pif)和虚拟网卡(vi

LeoDuo的专栏 3723

CS61B Project0

(一)git如何使用 首先是对git的使用。git是一个分布式的版本管理工具,其可以记录某一目录下的所有文件的不同版本。 git init把这个目录变成Git可以管理的仓库: $ git status 查询追踪状态 git add添加文件到git track的对象中 git commit把文件提交到仓库 ...

sinat_38195894的博客 2335

基于STM32L4XX、HAL库的ICM-42670-P姿态传感器驱动程序设计

sprintf(buffer, "温度: %.1f °C\r\n\r\n", sensor_data.temperature);sprintf(buffer, "陀螺仪: X=%.2f Y=%.2f Z=%.2f rad/s\r\n",sprintf(buffer, "加速度: X=%.2f Y=%.2f Z=%.2f m/s²\r\n",sprintf(buffer, "开始校准IMU,请保持传感器静止...\r\n");sprintf(buffer, "读取传感器数据失败\r\n");

zhusl6688的博客 647

基于互联网的智能旧衣回收箱设计与实现

本文介绍了基于嵌入式系统的智能旧衣回收箱的设计与实现,涵盖了硬件设计、软件开发、图像识别、物联网连接等方面的内容。通过利用最新的技术,如图像识别、物联网和云计算,实现了智能、便捷的旧衣物回收系统。未来,随着技术的不断进步,智能回收系统将会在环保领域发挥更大的作用。

2201_76125393的博客 913

CS61B+CS170

UCB的本科课程CS61B和CS170是利用java语言对数据结构与算法进行了详细的讲解,因为课程视频和slide都能获得,同时课程project设置合理,对于找工作所需的算法学习,特别是自学是一个不错的选择。 CS61B Homepage CS61B 视频...

一只小包子的博客 5842

【汽车 OTA 】差分升级

汽车 OTA 差分升级,本质是在整包 OTA 的基础上,通过“只传变化”的方式,大幅减少下载数据量、时间和成本,是当前车端软件升级的主流方向之一。

天赐好车的博客 498

Unity API——1

UnityEngine.Accessibility VisionUtility:在视觉性能上有一些...

qq_41234351的博客 1万+

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

CS61B sp2018笔记 | Lists

Lists 1. IntLists   下面我们来一步一步的实现List类,首先你可以实现一个最简单的版本: public class IntList { public int first; public IntList rest; public IntList(int f, IntList r) { first = f;...

隐秀_ 7216

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Berkeley CS61B Spring 2019 打卡(2)

2019 June 24 ||

weixin_41264869的博客 1105

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

CS61B sp2018笔记 | Introduction to Java

Introduction to Java Essentials 1. Reading 1.1 Hello World   这门课程虽然是用Java教授数据结构,但重点不在Java语法本身,所以最开始只是简单的讲了一些Java的要点: The program consists of a class declaration, which is declared ...

隐秀_ 4041

Heaps and PQs(The Priority Queue) | CS 61B Data Structures, Spring 2019

Heaps and PQs(The Priority Queue) The Priority Queue Interface If we want to cared more about quickly finding the smallest or largest element instead of quickly searching Now we come to the Abstract ...

yaoxinJJJ的博客 922

Red Black Trees | CS 61B Data Structures, Spring 2019

Red Black Trees | CS 61B Data Structures, Spring 2019 reading:11.4, 11.5, Algs 424-431, 432-448 (extra) Why we need Red black Trees Wonderfully balanced as they are, B-Trees are really difficult to im...

yaoxinJJJ的博客 857

Hashing | CS 61B Data Structures, Spring 2019

Hashing reading: 12.1, 12.2, 12.3, 12.4, 12.5, Algs 458-468, 478-479, 468-475 (extra) Lecture 19: Hashing Set Implementations, DataIndexedIntegerSet Integer Representations of Strings, Integer Overfl...

yaoxinJJJ的博客 688

Prefix Operations and Tries | CS 61B Data Structures, Spring 2019

Data Structures Summary The problem we are presented: Given a stream of data, retrieve(搜索) information of interest. All of the data structures we have discussed so far have been to solve the search pr...

yaoxinJJJ的博客 665

clab8 总结|CS 61B Data Structures, Spring 2019

实战总结 Lab 8: HashMap /****************************************************************************** * Compilation: javac SeparateChainingHashST.java * Execution: java SeparateChainingHashST &l...

yaoxinJJJ的博客 639

Lecture 25: Shortest Paths| CS 61B Data Structures, Spring 2019

Categories Summary So Far: DFS vs. BFS Dijkstra’s Algorithm Dijkstra’s Correctness and Runtime A* A* Heuristics (188 preview) demo1 demo2 >As we discussed last time, BFS would not be a good ch...

yaoxinJJJ的博客 516

Lecture 26: Minimum Spanning Trees | cs61b 2019

Lecture 26: Minimum Spanning Trees MST, Cut Property, Generic MST Algorithm Prim’s Algorithm Kruskal’s Algorithm Spanning Trees MST vs. SPT A shortest paths tree depends on the start vertex: Becau...

yaoxinJJJ的博客 463
上一篇: Lecture 26: Minimum Spanning Trees | cs61b 2019
下一篇: Decomposition and Reductions|cs61b 2019 lec 27 |图总结
yaoxinJJJ
博客等级 码龄7年 5粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值