Gullu - Optimal Substructure and Handshaking Lemma Flashcards
The edge a->b emanates from
a
The edge a->b is incident to
b
Adjacent Vertices
(in a->b the vertex b is adjacent to a)
Out-Degree of a Vertex:
Number of edges emanating from a node. Written as |A(v)|
In-Degree of a Vertex:
Number of edges incident on a node. Written as |I(v)|
The subgraph S of a graph G is a graph where
- Each vertex in S is a vertex V of G
- Each edge in S is a subset of the edges in G, and each vertex in edges of S is a vertex in S (implied because subgraph is a graph).
Connected Graph
There is a path between every pair of vertices.
Graph Representations
Common representations are the adjacency list and the adjacency matrix. Suppose the vertices of a graph are labelled with numbers 0 to n-1…
Adjacency List
- Adjacency List would then be a 2D array (n by n) of Boolean values
- A[i,j] true if there is an edge from i to j
- If a graph is unweighted then a value in the matrix is the weight
- If the graph is undirected, then A[i,j] = A[j,i]. This will make the matrix symmetrical about the diagonal.
Adjacency Matrix
the space complexity is O(|v|^2). This is irrespective of the number of edges in the graph. If |E| < |V^2| then the matrix will be sparse and inefficient, most values will be zero.
Suitability: Consider the operation of determining whether there is an edge between two vertices v1 and v2:
In adjacency matrix: Examine value of A[v1,v2]
In adjacency list: Locate v1 in the primary list, look for v2 in secondary list
Winner: Adjacency Matrix
Suitability: Find all vertices adjacent to a vertex v1 in a graph having n vertices
In adjacency matrix: Go to row for v1 and iterate over n columns
In adjacency list: Go to element v1 and the secondary list is the list of adjacency vertices
Winner: Adjacency list
The handshaking lemma
For undirected graphs, For example: There is a party in which some people shake hands, If i shake someones hand it follows that they shook my hand. There will be an even number of handshakes.
Spanning Trees
Concerns undirected and connected graph. A spanning tree is a tree that connects all the vertices in a graph and uses some edges.
The minimum spanning tree
Concerns connected and undirected graphs, The graph is weighted (edge weight function w:E->R).
The width of a spanning tree in the graph is the sum of weight it uses.
The minimum spanning tree is the spanning tree in the graph having the smallest weight.