1 | intro to networks; DFS and BFS Flashcards
(59 cards)
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
Incidence matrix
Shape?
Not always square