A graph is a mathematical representation of a set of objects and the connections or relationships between them. It consists of two main components: vertices (also known as nodes) and edges. It a non-linear data structure
- Vertices represents the entities, vertices are also known as vertex or nodes.
- Edges represents the relationship between the entities. An edge can be directed or undirected.
Mathematicaly we can also say that a graph G is an ordered pair of a set V of vertices and set E of edges
In computer science, graphs are commonly used in data structures, such as trees and networks, and in algorithms, such as search algorithms and pathfinding algorithms. They are also used in machine learning and artificial intelligence.
It is a graph G in which the edges does'nt have any direction.
It is a graph G in which the edges possess direction.
It can be directed or undirected graph G edges have a numerical value(weight).
A graph that contains at least one cycle is known as a cyclic graph.
A graph that contains zero cycles is known as an acyclic graph.
Note:
A cycle in context of graph occures when number of vertices are connected to one another in a closed chain of edjes.
A directed aCyclic graph ia one that is directed, but does not contain ANY cycles. These are also called DAG's for short.
Note:
- A DAG is the backbone of applications that handle scheduling for system of tasks, which needs to be processed in an order.
- It is the concept behind Dependency Graphs.
- It is used to represent a State Machine for objects that don't have " reversible " states.
It is the number of edges that are connected to it. It is a measure of how many neighbors a vertex has in the graph.
It is the highest degree exhibited by one of the vertex in G.
A connected graph is a graph where there exists a path between any two vertices in the graph. In other words, there are no isolated vertices in a connected graph.
If a graph is not connected, it is called a disconnected graph.
Note:
- A graph is said to be strongly connected if there is a directed path between every pair of vertices.
- A directed path in a graph is a sequence of vertices connected by directed edges, where the edges have a specific direction from one vertex to another. The path starts at one vertex and ends at another, following the direction of the edges along the way. A directed path represents a directed connection between two vertices in a directed graph.
- Adjacency Matrix
- Adjacency List (not needed now..)
- In case of an undirected graph, we need to show that there is an edge from vertex i to vertex j and vice versa. In code, we assign adj[i][j] = 1 and adj[j][i] = 1 .
- In case of a directed graph, if there is an edge from vertex i to vertex j then we just assign adj[i][j]=1 .
- In case of weighted directed graph: