圖由頂點 (Vertex) 和邊 (Edge) 組成,用來表示物件之間的關係。BFS 和 DFS 是最基本的圖遍歷演算法。
Notes:
- 圖的表示方式:鄰接矩陣 vs 鄰接表
- BFS 適合最短路徑(無權圖),DFS 適合連通性和路徑探索
- Union-Find 適合處理動態連通性問題
- 拓撲排序用於有向無環圖 (DAG) 的依賴關係
跨倉庫導讀#
- 對應理論章節:圖 ↗
#127
Word Ladder
#130
Surrounded Regions
#133
Clone Graph
#200
Number of Islands
#207
Course Schedule
#210
Course Schedule II
#261
Graph Valid Tree
#286
Walls and Gates
#323
Number of Connected Components in an Undirected Graph
#399
Evaluate Division
#417
Pacific Atlantic Water Flow
#463
Island Perimeter
#684
Redundant Connection
#695
Max Area of Island
#721
Accounts Merge
#752
Open The Lock
#785
Is Graph Bipartite?
#802
Find Eventual Safe States
#909
Snakes And Ladders
#934
Shortest Bridge
#953
Verifying An Alien Dictionary
#994
Rotting Oranges
#1020
Number of Enclaves
#1091
Shortest Path in Binary Matrix
#1129
Shortest Path with Alternating Colors
#1162
As Far from Land as Possible
#1254
Number of Closed Islands
#1462
Course Schedule IV
#1466
Reorder Routes to Make All Paths Lead to The City Zero
#1553
Minimum Number of Days to Eat N Oranges
#1557
Minimum Number of Vertices to Reach all Nodes
#1857
Largest Color Value in a Directed Graph
#1905
Count Sub Islands
#1958
Check if Move Is Legal
#2101
Detonate the Maximum Bombs
#2359
Find Closest Node to Given Two Nodes
#2477
Minimum Fuel Cost to Report to the Capital
#2492
Minimum Score of a Path Between Two Cities