1 | intro to networks; DFS and BFS Flashcards
Informal definition of a graph
a graph (𝐺)
- abstract representation of a set of components (nodes/vertices)
- where some pairs of the components are connected by links (edges).
Formal definition of a graph
- A graph is a pair 𝐺 =(𝑉,𝐸) , such that 𝐸 ⊆ {{𝑢, 𝑣}|𝑢, 𝑣 ∈ 𝑉}.
- We refer to 𝑉 as a set of nodes (or vertices) and 𝐸 as a set of edges.
Brackets for sets:
difference between {} and ()
{} = non ordered
() = ordered
Cartesian product of two sets?
eg A and B
A = {1, 2}
B = {3, 4, 5}
Cartesian Product of sets A and B is defined as the set of all ordered pairs (x, y) such that x belongs to A and y belongs to B.
Cartesian Product of A and B is {(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)}.
Cartesian product of the same set X = {x1, x2, …}?
X x X = {(x1, x1), (x1, x2), … | x1, x2, … ∈ X}
What do we know about E(G) and the cartesian product V(G) x V(G) ?
E(G) <= V(G) x V(G)
What is incidence in graph theory?
If 𝑒 = {𝑢, 𝑣} is an edge, then
- 𝑢 and 𝑣 are incident with 𝑒 (and vice versa)
- Elements from different sets (nodes/edges)
What is adjacence in graph theory?
Adjacence
- If 𝑒 = {𝑢, 𝑣} is an edge, then 𝑢 and 𝑣 are adjacent = are neighbors
- If 𝑒 = {𝑢, 𝑣} is an edge, and f = {u, w} is an edge then e and f are
adjacent = are neighbours
Elements from the same set (nodes/edges)
Can a node be adjacent to a node?
yes
Can a node be adjacent to an edge?
no, it’s incident to the edge
What is the cardinality of a graph?
𝑛 = |𝑉(𝐺)|
the number of nodes it contains
also known as order of the graph
What is a multi-edge?
Parallel edges
Two edges 𝑒 and 𝑓 are called parallel, if they connect the same vertices.
Simple graph?
A graph is called simple, if it does not contain multi-edges or loops.
Otherwise it is called a multi-graph.
Opposite of a simple graph?
multi-graph
Directed graph - formal definition?
From general graph definition:
- A directed graph is a pair 𝐺 =(𝑉, 𝐸) , such that 𝐸 ⊆ {(𝑢, 𝑣) | 𝑢, 𝑣 ∈ 𝑉}.
- We refer to 𝑉 as a set of nodes (or vertices) and 𝐸 as a set of (directed) edges.
additionally:
- For the edge 𝑒 = (𝑢, 𝑣), 𝑢 is the head and 𝑣 is the tail
Weighted directed graph?
- Directed graph with a weight function 𝑤: 𝐸 → ℝ.
- Eg: V = {v1, v2}; e1 = (v1, v2), w(e1) = 2
- Weight = distance / resource availability / capacity etc
Ways to represent a graph on a computer ?
Adjacency matrix
Incidence matrix
Adjacency list
Adjacency matrix
Rows and columns?
Nodes and nodes
OR
Edges and edges
Adjacency matrix - undirected graphs
Values in the matrix?
- 𝐴[𝑢, 𝑣] = 1 𝑖𝑓 (𝑢, 𝑣) ∈ 𝐸(𝐺)
- 𝐴[𝑢, 𝑣] = 0 𝑖𝑓 (𝑢, 𝑣) ∉ 𝐸(𝐺)
- Edge weights can be considered (instead of 1).
Adjacency matrix - undirected graphs
Complexity to check for presence of an edge between two nodes
Constant time
Adjacency matrix - undirected graphs
Shape?
Symmetry?
Always square
Symmetric
Adjacency matrix - directed graphs
Shape? Symmetry?
Always square
May not be symmetrical
Adjacency matrix - only for nodes?
No, can also be for edges