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.

🕑

1. 绘制图: 您可以绘制任何未加权的有向图作为输入图（绘制双向边 (u, v) ，您可以绘制两个有向边 u → v and v → u ）。
2. 示例图: 您可以从我们选择的示例图列表中进行挑选，以帮助您入门。

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?

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

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?

It is still O(V+E)
Calling O(V+E) DFS/BFS V times, so O(V*(V+E)) = O(V^2 + VE)
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?

Always BFS
Always DFS
It Depends on the Situation
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.

🕑

SCC 算法

2-SAT 检查

>

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

s =

s =

DFS 版本

BFS 版本 (Kahn's 算法)

DFS 版本

BFS 版本

Kosaraju 算法

Tarjan 算法

We use cookies to improve our website.
By clicking ACCEPT, you agree to our use of Google Analytics for analysing user behaviour and improving user experience as described in our Privacy Policy.
By clicking reject, only cookies necessary for site functions will be used.

#### 关于

VisuAlgo于2011年由Steven Halim博士创建，是一个允许学生以自己的速度自学基础知识，从而更好地学习数据结构与算法的工具。
VisuAlgo包含许多高级算法，这些算法在Steven Halim博士的书（“Competitive Programming”，与他的兄弟Felix Halim博士合作）和其他书中有讨论。今天，一些高级算法的可视化/动画只能在VisuAlgo中找到。

VisuAlgo不是从一开始就设计为在小触摸屏（例如智能手机）上工作良好，因为为了满足许多复杂算法可视化，需要大量的像素和点击并拖动手势进行交互。为得到良好的用户体验，最低屏幕分辨率应为1024x768，并且本网站只有首页相对适合移动设备。但是，我们正在测试一个准备在2022年4月发布的移动版本。
VisuAlgo是一个正在进行的项目，更复杂的可视化仍在开发中。

VisuAlgo支持三种语言：英语，中文，印尼语。目前，我们还以各种语言写了有关VisuAlgo的公共注释：
id, kr, vn, th.

#### 团队

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

Koh Zi Chun, Victor Loh Bo Huai

Phan Thi Quynh Trang, Peter Phandi, Albert Millardo Tjindradinata, Nguyen Hoang Duy

Rose Marie Tan Zhao Yun, Ivan Reinaldo

Jonathan Irvin Gunawan, Nathan Azaria, Ian Leow Tze Wei, Nguyen Viet Dung, Nguyen Khac Tung, Steven Kester Yuwono, Cao Shengze, Mohan Jishnu

Erin Teo Yi Ling, Wang Zi

Truong Ngoc Khanh, John Kevin Tjahjadi, Gabriella Michelle, Muhammad Rais Fathin Mudzakir

Liu Guangyuan, Manas Vegi, Sha Long, Vuong Hoang Long

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

#### 使用条款

VisuAlgo is free of charge for Computer Science community on earth. If you like VisuAlgo, the only "payment" that we ask of you is for you to tell the existence of VisuAlgo to other Computer Science students/instructors that you know =) via Facebook/Twitter/Instagram/TikTok posts, course webpages, blog reviews, emails, etc.

If you are a data structure and algorithm student/instructor, you are allowed to use this website directly for your classes. If you take screen shots (videos) from this website, you can use the screen shots (videos) elsewhere as long as you cite the URL of this website (https://visualgo.net) and/or list of publications below as reference. However, you are NOT allowed to download VisuAlgo (client-side) files and host it on your own website as it is plagiarism. As of now, we do NOT allow other people to fork this project and create variants of VisuAlgo. Using the offline copy of (client-side) VisuAlgo for your personal usage is fine.

Note that VisuAlgo's online quiz component is by nature has heavy server-side component and there is no easy way to save the server-side scripts and databases locally. Currently, the general public can only use the 'training mode' to access these online quiz system. Currently the 'test mode' is a more controlled environment for using these randomly generated questions and automatic verification for real examinations in NUS.

List of Publications

This work has been presented briefly at the CLI Workshop at the ICPC World Finals 2012 (Poland, Warsaw) and at the IOI Conference at IOI 2012 (Sirmione-Montichiari, Italy). You can click this link to read our 2012 paper about this system (it was not yet called VisuAlgo back in 2012) and this link for the short update in 2015 (to link VisuAlgo name with the previous project).

This work is done mostly by my past students.

Bug Reports or Request for New Features

VisuAlgo is not a finished project. Dr Steven Halim is still actively improving VisuAlgo. If you are using VisuAlgo and spot a bug in any of our visualization page/online quiz tool or if you want to request for new features, please contact Dr Steven Halim. His contact is the concatenation of his name and add gmail dot com.

#### 隐私政策

Version 1.1 (Updated Fri, 14 Jan 2022).

Disclosure to all visitors: We currently use Google Analytics to get an overview understanding of our site visitors. We now give option for user to Accept or Reject this tracker.

Since Wed, 22 Dec 2021, only National University of Singapore (NUS) staffs/students and approved CS lecturers outside of NUS who have written a request to Steven can login to VisuAlgo, anyone else in the world will have to use VisuAlgo as an anonymous user that is not really trackable other than what are tracked by Google Analytics.