Union-Find Algorithm
Find RootThis tree graph can be described by a parent table.parent = [0, 1, 1, 1, 3, 3, 6, 6], representing the parent node for each node. (including node 0, although it is not used.)parent[1] = 1, parent[6] = 6. They are roots of the other nodes, since their parents are themselves.parent[2] = parent[3] = 1, parent[4] = parent[5] = 3, parent[7] = 6.The root of each node can be found using the pa..
Dijkstra’s Algorithm
Our goal is to find the length of the shortest path to reach each node from the given start node.Use DP (Dynamic Programming) table to record and update the shortest path and its length.ProcessInitialize the DP table:d = [inf, inf, inf, inf, inf], distances from A to A, B, C, D, E. (inf represents infinity.)p = [[], [], [], [], []], paths from A to A, B, C, D, E.v = [False, False, False, False, ..