A graph is a pair of sets where is a set of vertices and is a set of edges.
- If is a set of unordered pairs, the graph is called undirected. If is a set of ordered pairs, the graph is called directed.
- if self-loop allowed in undirected graph depend on given questions.
- Weight of edge is a function where is the weight of edge
- A matching is a subset of edges that those edges that do not share any end points
- every vertex in one matching then this matching is perfect
- two vertices are adjacent if
- one is called neighbor of the other
- an edge (u,v) is incident on vertices u and v. In a directed graph, the terminology differentiates between the beginning and ending vertex of an edge. So edge (u,v) which leaves vertex u is said to be incident from vertex u and is incident to (or enters) vertex v
- A sequence of distinct vertices is a path from to if for every and are adjacent.
- The length of the path is the number of edges in the path.
- A simple path contains no repeated edge
- A sequence of distinct vertices is a the cycle if is a path, and
- A cycle is called Hamiltonian if every vertex appear in the cycle exactly once (except for the start/end vertex which appears twice)
- A simple circle contains no repeated edge
- A -(vertex) coloring of is a function ,
- Connected: there is some path from to
- acyclic: no cycle in graph
- independent set: , is an independent set
- In an undirected graph, the degree of a vertex is the number of edges incident on . In a directed graph, the in-degree of vertex is the number of edges incident to (the size of set ) and the out-degree is the number of edges incident from v (the size of set ).
- A connected component is a group of nodes that are connected by edges
The adjacvency-list representation of a graph consists of an array Adj , one for each vertex in . For each , the adjacency list contains all the vertices such that .
- Use space complexity
The adjacency-matrix representation of a graph consists of a matrix such that is 1 if and 0 otherwise where this such matrix is .
- Use space complexity
We always prefer the adjacency-list representation of a graph because it is more space-efficient than the adjacency-matrix representation and get more robustness in which we can augment on the node of the linked list so that we can present weight graph.
Some examples about Graph:
- locations on maps, relationship between people(contact facing), Courses, WIFI Connection, Trees, vector graph, airport routes, functions, binary relations
Matching Problem:
- input: a graph with weight
- output: A matching (usually maximum/minimum)
Pathing Finding Problem:
- Input: a graph and two vertices
- output: A path between two vertices
Travelling Salesman Problem:
- Input: a graph and a start vertex
- Output: a Hamiltonian cycle minimizes the total edge weights
Coloring Problem:
- input: a graph
- output a k-coloring of the graph
Independent Set Problem:
- input: a graph, a number with
- output: An independent set of size