MindMap Gallery Python Algorithm 5. Traversal the universal key to the algorithm
"Python Algorithm" 5. Traversal: The Master Key of Algorithms - Key: Traversal - the Master Key in Algorithm Abstract: 1. Introduction 2. Park Maze Walk 3. Wireless Maze and Shortest (Unweighted) Path Problem 4. Strongly Connected Components
Edited at 2022-06-14 21:57:27Avatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
Avatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
"Python Algorithm" 5. Traversal: the master key of the algorithm
Overview
Graph traversal
Discover and then visit all nodes in the graph
example
floodfill
GIMP/PS paint bucket
Extract several connected points from a region and separate them from other adjacent regions
Ex5-4
n people, n jobs, each person has skills corresponding to specific jobs
Ch10
Dungeons and Dragons
Room: Node
Already visited
knew
unknown
door: side
use
direct
Key components or principles of other algorithms
Ch9,10
Code
Traverse connected components using adjacency sets
Find connected components
sidebar
The problem of the Seven Bridges of Königsberg
Euler diagram
Even degrees
"Traveling the World" Question
Hamiltonian graph
Is it possible to traverse each vertex of the regular 12-hedron exactly once and then return to the original place?
Taking a walk in the zoo is serious business
No loops allowed
At this time, the strategy of walking on one side is effective
Traverse the tree
judge
no inner wall
Can lay a continuous wallpaper
Each barrier has exactly one connection point with the exterior wall
Discover all points and follow all paths twice (one direction each time)
recursion
Code
Backtracking
How to stop circling
Description of Lucas
Mark every entry/exit intersection
If possible, avoid crossing intersections that have already been visited and avoid taking paths that have already been traveled
Code
depth first
depth first traversal
Code
Iterate
stack
Universal
replace queue
directed graph
Consider it in terms of an undirected graph
Depth-first timestamps and topological sorting
Timestamp
time of discovery
Backtracking time passed
Code
DFS with timestamp
DFS-based topological sorting
DFS properties
Each node is found before the descendants of the DFS tree
Each node is completed after the descendants of the DFS tree
Topological sorting using DFS
Ch4
Notice
Explicitly include a for loop to ensure that each node is traversed
The check whether a node is already in the history is placed in the recurse() function
The recurse() function is an internal function, pay attention to the scope
Nodes in descending order of completion time
Traversal order
prologue
mid-order
Afterword
sidebar
Node colors and edge types
Node type
unknown
in queue
Already visited
Node coloring proposed by Introduction to Algorithms
initially white
gray between discovery and completion
Finished black
Trémaux's algorithm
Gray intersections are seen, but avoided
The black intersection requires backtracking
edge color
If edge uv is found
v white: the edge is part of the traversed tree
v gray: back edge (edge from a node to an ancestor node)
v black: forward edge (edge from one node to its descendants) or across edge (neither nor)
Can be represented by timestamp
There may not be much need for classification, but it has an important purpose
If a loop edge is found, it means there is a loop, otherwise there is no loop.
Endless maze and shortest path without rights
endless maze
will not return
shortest path
DFS is highly likely to be wrong
Detour
IDDFS
Mark entrances and exits of pathways
first step
If it starts at intersection a
First visit all intersections with a path, and return to the starting point each time
If it's a dead end, mark it closed after returning
Every intersection that takes you to a closed point is also marked closed
Step 2
through an open passage
Now there are two markers on it
Assume it is point b, traverse all open paths of b
After completion, return to a and proceed to the next opening of a until all are two marks
Step n
All open paths starting from a now have n-1 markers
Remove all neighbors of a and mark until all n-1
Code
operation hours
Nodes and edges will be traversed multiple times, and the worst case reaches square
Trees generally have many nodes at the bottom and can be close to linear
find the exact distance
Add additional logging information
Maintain a distance table
A distance dictionary and a parent node dictionary to facilitate finding the shortest path
BFS
breadth first search
Code
There is only one case where IDDFS is better than BFS
Search a huge tree
Because there is no loop, there is no need to record visited nodes.
IDDFS only stores the path back to the starting point
BFS must ensure that all edges are in memory and grow exponentially when branching
sidebar
deque
Python lists
LIFO is good
Poor FIFO
Adding elements at the end is constant
Removing elements at the head of the queue is linear
bidirectional list deque
collections module
Strongly connected component
concept
Strong connectivity
Vertices u and v can reach each other
Strongly connected graph
Every two vertices of the directed graph G are strongly connected.
Strongly connected component
Maximum strongly connected subgraph of non-strongly connected graph
DFS
Possibly traverse from multiple starting points in order to traverse the entire graph
If the strongly connected component X has an edge to Y, then the final completion time of X is later than Y
super node
Form DAG
Start with SCC without incoming edges
Kosaraju algorithm
Run the dfs_topsort function on the graph to get the sequence seq
Invert all edges
Do a complete traversal, selecting the starting point from seq (in order)
Code
Kosaraju
sidebar
Targets and pruning
goal oriented
pruning
A* algorithm
Ch9
branch and bound
Ch11
Further reading
Traverse
Book
by Cormen et al
Strongly connected component
Tarjan's and Gabow's algorithm