1x

1. 拓扑排序算法（包括DFS和BFS/Kahn的算法版本），
2. 二分图检查器算法（包括DFS和BFS版本），
3. 切割顶点和桥的查找算法，
4. 强连通分量（SCC）查找算法
(Kosaraju的和Tarjan的版本)，
5. 以及2-SAT检查算法。

Remarks: By default, we show e-Lecture Mode for first time (or non logged-in) visitor.
If you are an NUS student and a repeat visitor, please login.

🕑

Pro-tip 1: Since you are not logged-in, you may be a first time visitor (or not an NUS student) who are not aware of the following keyboard shortcuts to navigate this e-Lecture mode: [PageDown]/[PageUp] to go to the next/previous slide, respectively, (and if the drop-down box is highlighted, you can also use [→ or ↓/← or ↑] to do the same),and [Esc] to toggle between this e-Lecture mode and exploration mode.

🕑

There are two different sources for specifying an input graph:

1. Edit Graph: You can draw a new graph or edit an example unweighted directed graph as the input graph (to draw bidirectional edge (u, v), you can draw two directed edges u → v and v → u).
2. Example Graphs: You can select from the list of our selected example graphs to get you started.

Pro-tip 2: We designed this visualization and this e-Lecture mode to look good on 1366x768 resolution or larger (typical modern laptop resolution in 2021). We recommend using Google Chrome to access VisuAlgo. Go to full screen mode (F11) to enjoy this setup. However, you can use zoom-in (Ctrl +) or zoom-out (Ctrl -) to calibrate this.

🕑

Quiz: Mini pre-requisite check. What are the Pre-/In-/Post-order traversal of the binary tree shown (root = vertex 0), left and right child are as drawn?

Post = 4, 3, 2, 1, 0
In = 1, 0, 3, 2, 4
In = 4, 2, 3, 0, 1
Pre = 0, 2, 4, 3, 1
Post = 1, 3, 4, 2, 0
Pre = 0, 1, 2, 3, 4

Pro-tip 3: Other than using the typical media UI at the bottom of the page, you can also control the animation playback using keyboard shortcuts (in Exploration Mode): Spacebar to play/pause/replay the animation, / to step the animation backwards/forwards, respectively, and -/+ to decrease/increase the animation speed, respectively.

🕑

PS：从技术上来讲，这种转换是通过运行我们即将探索的 DFS(0) 来实现的。
🕑

🕑

The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.

If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.

FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

🕑

🕑

🕑

DFS 采用一个输入参数：源点 s
DFS 是最基本的图的算法之一，因此请花时间了解该算法的关键步骤。
🕑

DFS类比一个只有一个人口和一个出口的迷宫。您在 入口处，想要探索迷宫到达出口。显然你不能分身。

🕑

🕑

🕑

DFS 用另一个大小为 V 个顶点数组 p[u] 来记住在DFS遍历路径上每一个顶点 uparent/predecessor/previous（父/祖先/前）顶点。

🕑

🕑

DFS 的时间复杂度是 O(V+E) ，因为：

1. 每个节点只访问过一次，因为 DFS 将仅递归地探索节点 u 如果 status[u] = unvisited — O(V)
2. 每次访问完一个节点，都会探索其所有 k 个邻点，因此在访问所有节点之后，我们已检查了所有 E 边 — （O(E) ，因为i每个节点的邻点总数等于 E）。
🕑

DFS 的he O(V+E) 时间复杂度只有当我们可以在 O(k) 时间内访问一个顶点的所有 k 个邻点时才可以实现。

Quiz: Which underlying graph data structure support that operation?

Edge List

🕑

The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.

If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.

FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

🕑

DFS 和 BFS 都有自己的优点和缺点。学习两者并对正确的情况采用正确的图遍历算法是非常重要的。
🕑

🕑

BFS 与之前讨论过的非常相似，但有一些差异。

BFS 从源点 s 开始，但它在更深入之前使用 queue 尽最宽可能地将访问序列排序。

BFS 还是用大小为 V 节点的布尔数组来区分两种不同的状态：已访问节点和未访问节点（我们不会像使用 DFS 那样使用 BFS 来检测反向边）。

🕑

🕑

BFS的时间复杂度是 O(V+E)，因为:

1. 每一个顶点都被访问一次 因为它们只能进入队列一次— O(V)
2. 每当一个顶点从队列中出队时，所有它的 k 个邻居都会被探索 所以当所有的顶点都被访问过后，我们一共探索了 E 条路径 — (O(E) 因为每个顶点的邻居总数为 E).

🕑

1. 检测可达性
2. 显示出遍历路径
3. 分辨/计数/标记 一个无向图的连通分量（CCs）
4. 探测图是否有圈（cyclic）
5. 拓补排序（只在有向无圈图 DAG中）

🕑

🕑

`method backtrack(u)  if (u == -1) stop  backtrack(p[u]);  output vertex u`

backtrack 去返回 (t)。示例： s = 0t = 4，您可以调用 DFS(0) 然后backtrack(4)Elaborate

🕑

🕑

`CC = 0for all u in V, set status[u] = unvisitedfor all u in V  if (status[u] == unvisited)    CC++ // 我们可以用CC计数器的数量来作为CC的标记    DFS(u) // 或者 BFS(u), 来标记它的成员为已访问output CC // 上面的示例图的答案是3// CC 0 = {0,1,2,3,4}, CC 1 = {5}, CC 2 = {6,7,8}`

🕑

Quiz: What is the time complexity of Counting the Number of CCs algorithm?

Calling O(V+E) DFS/BFS V times, so O(V*(V+E)) = O(V^2 + VE)
It is still O(V+E)
Trick question, the answer is none of the above, it is O(_____)

🕑

The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.

If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.

FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

🕑

🕑

1. 未访问: 和之前一样，DFS还没有访问过 u
2. 已探索: DFS已经访问了 u, 但是至少有一个 u 的邻居还没有被探索 (DFS会先 深度优先 式的先去探索那个顶点的邻居),
3. 已访问: 增强版的定义：顶点 u 的所有邻居都已经被探索过了并且DFS正要从顶点 u 原路返回去顶点 p[u].

🕑

🕑

DAG 的拓扑排序是此 DAG 的节点的线性排序，其中每个节点位于其传出边所连接的所有节点之前。

DAG拓扑排序的主要目的是用于 Dynamic Programming (DP) 技术。例如，此拓扑排序过程在 DP solution for SSSP on DAG内部使用。
🕑

BFS 版本基于没有传入边的节点的概念，也称为 Kahn 算法.。在示例的DAG上尝试 Toposort (BFS/Kahn's)
🕑

1. 检测二分图 (DFS 和 BFS 变种),
2. 寻找无向图的衔接点（切顶）和桥梁（仅DFS）,
3. 寻找有向图的强连通分量（SCC）（Tarjan和Kosaraju的算法）, 以及
4. 2-SAT(可满足性) 检查算法.

🕑

🕑

🕑

🕑

🕑

Quiz: Which Graph Traversal Algorithm is Better?

It Depends on the Situation
Always DFS
Always BFS
Both are Equally Good

🕑

The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.

If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.

FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

🕑

🕑

🕑

🕑

The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.

If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.

FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

You have reached the last slide. Return to 'Exploration Mode' to start exploring!

Note that if you notice any bug in this visualization or if you want to request for a new visualization feature, do not hesitate to drop an email to the project leader: Dr Steven Halim via his email address: stevenhalim at gmail dot com.

🕑

Visualisation Scale

Toggle V. Number for 0.5x

SCC 算法

2-SAT 检查

>

1.0x (Default)

0.5x (Minimal Details)

CP3 4.1

CP3 4.3

CP3 4.4 DAG

CP3 4.9

CP3 4.17 DAG

CP3 4.18 DAG, Bipartite

CP3 4.19 Bipartite

Large Graph

Large, Cycles

s =

s =

DFS 版本

BFS 版本 (Kahn's 算法)

DFS 版本

BFS 版本

Kosaraju 算法

Tarjan 算法

#### 关于

VisuAlgo最初由副教授Steven Halim于2011年构思，旨在通过提供自学、互动式学习平台，帮助学生更深入地理解数据结构和算法。

VisuAlgo涵盖了Steven Halim博士与Felix Halim博士、Suhendry Effendy博士合著的书《竞技编程》中讨论的许多高级算法。即使过去十年，VisuAlgo仍然是可视化和动画化这些复杂算法的独家平台。

VisuAlgo仍然在不断发展中，正在开发更复杂的可视化。目前，该平台拥有24个可视化模块。

VisuAlgo配备了内置的问题生成器和答案验证器，其“在线测验系统”使学生能够测试他们对基本数据结构和算法的理解。问题根据特定规则随机生成，并且学生提交答案后会自动得到评分。随着越来越多的计算机科学教师在全球范围内采用这种在线测验系统，它可以有效地消除许多大学标准计算机科学考试中手工基本数据结构和算法问题。通过给通过在线测验的学生分配一个小但非零的权重，计算机科学教师可以显著提高学生对这些基本概念的掌握程度，因为他们可以在参加在线测验之前立即验证几乎无限数量的练习题。每个VisuAlgo可视化模块现在都包含自己的在线测验组件。

VisuAlgo已经被翻译成三种主要语言：英语、中文和印尼语。此外，我们还用各种语言撰写了关于VisuAlgo的公开笔记，包括印尼语、韩语、越南语和泰语：

id, kr, vn, th.

#### 团队

Associate Professor Steven Halim, School of Computing (SoC), National University of Singapore (NUS)
Dr Felix Halim, Senior Software Engineer, Google (Mountain View)

CDTL TEG 1: Jul 2011-Apr 2012: Koh Zi Chun, Victor Loh Bo Huai

Jul 2012-Dec 2013: Phan Thi Quynh Trang, Peter Phandi, Albert Millardo Tjindradinata, Nguyen Hoang Duy
Jun 2013-Apr 2014 Rose Marie Tan Zhao Yun, Ivan Reinaldo

CDTL TEG 2: May 2014-Jul 2014: Jonathan Irvin Gunawan, Nathan Azaria, Ian Leow Tze Wei, Nguyen Viet Dung, Nguyen Khac Tung, Steven Kester Yuwono, Cao Shengze, Mohan Jishnu

Jun 2014-Apr 2015: Erin Teo Yi Ling, Wang Zi
Jun 2016-Dec 2017: Truong Ngoc Khanh, John Kevin Tjahjadi, Gabriella Michelle, Muhammad Rais Fathin Mudzakir
Aug 2021-Apr 2023: Liu Guangyuan, Manas Vegi, Sha Long, Vuong Hoang Long, Ting Xiao, Lim Dewen Aloysius

Optiver: Aug 2023-Oct 2023: Bui Hong Duc, Oleh Naver, Tay Ngan Lin

Aug 2023-Apr 2024: Xiong Jingya, Radian Krisno, Ng Wee Han

List of translators who have contributed ≥ 100 translations can be found at statistics page.

NUS教学与学习发展中心（CDTL）授予拨款以启动这个项目。在2023/24学年，Optiver的慷慨捐赠将被用来进一步开发 VisuAlgo。

#### 使用条款

VisuAlgo并不是一个完成的项目。Steven Halim副教授仍在积极改进VisuAlgo。如果您在使用VisuAlgo时发现任何可视化页面/在线测验工具中的错误，或者您想要请求新功能，请联系Steven Halim副教授。他的联系方式是将他的名字连接起来，然后加上gmail dot com。