See also slides
Node as information and edges as relationship between data
Directed acyclic graph (DAG)
Application: Merkle DAG
undirected.
- : set of vertices
- : set of undirected edges:
path is a sequence of nodes and edges connect two nodes.
A graph is connected if there is a path between every pair of vertices.
In a weight undirected graph each edge has a weight:
See also Graph isomorphism
directed.
- : set of vertices
- : set of edges containing node pairs:
path difference
sequence of nodes and edges are directional, edges are ordered pairs.
cycle
path with at-least one edge from a node
Strongly component: maximal sub-graph in which all node pairs are strongly connected.
matrix representation
Let be a directed graph with
Let matrix
For every pairs of nodes set
The adjacency list representation
Important
Let be an array of bags For every edge add to to bag
ops | complexity |
---|---|
add/remove nodes | (copy array) |
add/remove edges | (adding to bag) |
check an edge exists | (searching bags) |
iterate over all incoming edges of | (scan all bags) |
iterate over all outgoing edges of | (scan a bag) |
Check or change the weight of |
comparison.
Dense graph: > Sparse graph:
Traversing undirected graph.
Depth-first search (DFS)
Conclusion
- all nodes to which is connected
- is not a connected graph
- The order of recursive call determines all is connected to.
Complexity
- memory for marked and at-most recursive calls
- inspect each node at-most once and traverse each edge once:
Connected-components
Two-colourability
Bipartite graph
A graph is bipartite if we can partition the nodes in two sets such that no two nodes in the same set share an edge.
Breadth-first search (BFS)
Single-source shortest path
Given an undirected graph without weight and node , find a shortest path from node to all nodes can reach.