Last Minute Flashcards
topological sort
O(N+M) = O(V+E)
DFS/BFS
O(M) = O(E) with adj. list.
O(V^2) for adj. matrix
non weighted shortest path
O(N + M) with adjacency
dijkstras
with heap O((N+M)lgN) = O(MlgN) = O(ElogV)
with adjlist O(Dv)
with adj matrix O(V^2) = O(N^2)
all pairs shortest path
O(N^3) with N*O(N^2) dijkstras
with disjkstras heap O(MNlgN)
with dynamic programming we get O(N^3) with better constants
transitive closuer
N DFS = O(N(N+M))
adj matrix O(N^3)
prims-min spanning tree
O(ElogV) = O(MlogN)
kurskals min spanning tree
O(ElogV) = O(MlogN)
sum of all degrees for a graph
2M
undirected graph
M <= (N(N-1))/2
directed graph
M <= N(N-1)
connected graph
M >= N -1
tree
M = N -1
Forrest
M<= N -1
Binary tree with h levels
2^h -1 nodes