Cycle: a path from a vertex to itself
0-1-4-0
0-1-0
0
Simple Cycle: with at least one edge and without repeated edges
Tree: a connected graph without simple cycles
Definitions:
a connected graph with no simple cycles
a vertex, or two trees connected by an edge (rec)
a vertex, or a tree connected to a vertex by an edge (rec)
a connected graph with v vertices and v-1 edges
a connected graph with exactly 1 path between any two vertices
Forest: a graph where each connected component is a tree (notice a tree is a forest)
a graph with (connected or not) no simple cycles
a graph with at most one path between any two vertices
a forest with v vertices has at most v-1 edges
DFS, BSF complexity of a tree: O(v) reduced from O(v+e) unlike graph
BST: a tree where every vertex has at most 3 edges
two children, one parent
ordering invariant
root = any vertex with at most 2 edges
Space: O(v)
providing a path from every vertex to every other vertex
subgraph: a subgraph of graph G is a graph with the same vertices and a subset of its edges
spannning tree: a spannning tree for G is a subgraph that
has the same connectivity as G
and is a tree
spanning forest: a spanning forest for G is a subgraph that (a bunch of spanning trees)
has the same connectivity as G
and is a forest
Start with a spanning forest of singleton trees and add edges from the graph as long as they don't form a cycles (def.B)
Initialize T with isolated vertices of G (O(1)=graph_new)
For each edge (u, v) in G: (O(e))
if connected(u, v): (O(v) where v=v_in_tree_so_far by DFS/BFS)
discard the edge
else:
add it to T (O(1))
stop once T has v-1 edges
costs O(ev)
- O(v^2) for sparse graphs
(it can create spanning forests) (Edge-Centric algorithm is greedy, DFS/BFS is not since they have worklist)
first connect all notes
build a spanning tree
pick a start and an end
solving a maze is BFS/DFS
Start with a single vertex in the tree and add edges to vertices not in the tree (def.C) (Complexity: O(e) as DFS/BFS)
Minimum spanning tree: one with the least total weight of its edges.
total is O(ev)
sort is O(e log(e))
O(ev)
check if two point to the same representative (O(v))
merge representative, always have 2 choice (don't merge node) O(1)
stop once T has v-1 edges
store length in root as negative
merge shorter trees into taller trees
initialize array into "-1"s
A tree T of height h has at least 2^{h-1} vertices
A tree T with v vertices has height at most log(v)+1 (balanced tree = O(log v), for loop O(e), total O(eloge + elog v), assume sparse O(eloge))
grows very fast, inverse grows slow
adding/removing edges is O(log e) in priority queue
complexity O(e log e)
Table of Content