

A disconnected graph may consist of two or more connected graphs. Disconnected Graph: A graph is said to be disconnected if there is no path between a pair of vertices is called a disconnected graph.Strongly Connected Graph: A graph in which nodes can be visited by a single path is called a strongly connected graph.Weekly Connected Graph: A graph in which nodes cannot be visited by a single path is called a weekly connected graph.Note that a graph with only a vertex is a connected graph. Connected Graph: A graph is said to be connected if there exists at least one path between every pair of vertices.While in the directed graph we cannot return from the same path. Note that we can use the same path for return through which we have traversed. In an undirected graph, we can traverse in any direction. Undirected Graph: A graph in which edges are bidirectional is called an undirected graph.The following figure represents a directed graph. Note that in a directed graph, we can move either in one direction or in both directions. Direction denotes the way to reach from one node to another node. In a directed graph, we use arrows instead of lines (edges). Directed Graph: A graph in which edges represent direction is called a directed graph.The following figure represents an unweighted graph. Unweighted Graph: A graph in which edges are not associated with any value is called an unweighted graph.The following figure represents a weighted graph. It is used to calculate the cost of traversing from one vertex to another. Weighted Graph: In a weighted graph, each edge contains some data (weight) such as distance, weight, height, etc.Path: The path is a way to reach a destination from the initial point in a sequence. For example, the distance between two cities is 100 km, then the distance is called weight for the edge. For example, a path to the bus stop from your house. It represents the relation between the vertices.

For example, house, bus stop, etc.Įdge: An edge is a line that connects two vertices. To construct a graph there must be at least a node. It is denoted by a circle and it must be labeled. Vertex: Vertices are the point that joints edges. Edges are denoted by a line that connects nodes (vertices). Vertex is denoted by a circle with a label on them. Where vertex represents the data and edge represents the relation between them.

The examples of graph are a social media network, computer network, Google Maps, etc.Įach graph consists of edges and vertices (also called nodes). In other words, a graph G (or g) is defined as a set of vertices (V) and edges (E) that connects vertices. GraphĪ graph is a data structure that stores connected data. Also, we will learn the types of Graph, their implementation, and traversal over the graph. In this section, we will learn Java Graph data structure in detail. It represents a network that connects multiple points to each other.

The concept of the graph has been stolen from the mathematics that fulfills the need of the computer science field. In Java, the Graph is a data structure that stores a certain of data.
