You are on page 1of 4

Graphs:

A graph is an ordered pair, G = (V, E), of two sets representing the nodes or vertices of the graph
and the edges of the graph. An edge specifies which nodes have a connection between them. When
working with graphs, we are frequently interested in how these edges can be put together to move
through the graph.

A graph can either be undirected or directed. An undirected graph, typically just called a graph,
has edges that can be traversed in either direction.

Undirected graphs have edges that do not have a direction. The edges indicate a two-
way relationship, in that each edge can be traversed in both directions. This figure shows a simple
undirected graph with three nodes and three edges.

A directed graph, also called a digraph, has edges that can only be traversed in one direction.

Directed graphs have edges with direction. The edges indicate a one-way relationship, in that each
edge can only be traversed in a single direction. This figure shows a simple directed graph with
three nodes and two edges.
A graph is a set of points, called nodes or vertices, which are interconnected by a set of lines
called edges.

1 If a set representing an edge has just one element, that represents an edge that “loops,” or in other
words, starts and ends at the same node.

2 In a digraph, an ordered pair that has the same label for both components represents an edge that
starts and ends on the same node.
COMPLETE GRAPH:

A complete graph is a graph in which each pair of vertices is joined by an edge. A complete graph
contains all possible edges. s. If there are N nodes, there will be (N2 N) / 2 edges in a complete graph
without loop edges. A complete digraph is a digraph with an edge allowing traversal between every pair
of nodes. Because the edges of a graph allow travel in two directions, whereas a digraph’s edges allow
travel in only one, a digraph with N nodes will have twice as many edges, specifically N2 N.

A graph in which every pair of vertices is joined by exactly one edge is called complete graph. It
contains all possible edges.

A complete graph with n vertices contains exactly nC2 edges and is represented by Kn.

Example

In the above example, since each vertex in the graph is connected with all the remaining vertices
through exactly one edge therefore, both graphs are complete graph.

Weighted Graph

A weighted graph is a graph whose edges have been labeled with some weights or numbers.

The length of a path in a weighted graph is the sum of the weights of all the edges in the path.

Example:

In the above graph, if path is a -> b -> c -> d -> e -> g then the length of the path is 5 + 4 + 5 + 6 + 5 =
25.
When working with weighted graphs, we consider the weight to be the cost for traversing the edge.
A path through a weighted graph has a cost that is the sum of the weights of each edge in the path.
In a weighted graph, the shortest path between two nodes is the path with the smallest cost, even if
it doesn’t have the fewest edges. For example, if path P1 has five edges with a total cost of 24, and
path P2 has three edges with a total cost of 36, path P1 will be considered the shorter path because
its cost is less.

A graph or digraph is called connected if there is at least one path between every pair of nodes. A
cycle is a path that begins and ends at the same node. An acyclic graph or digraph is one that has no
cycles. A graph that is connected and acyclic is called an unrooted tree. An unrooted tree has the
structure of a tree except that no node has been specified as the root (but every node could serve as
the root).

Acyclic Graph

A graph which does not contain any cycle in it is called as an acyclic graph.

Example

Since, the above graph does not contain any cycle in it therefore, it is an acyclic graph.

Connected Graph

A connected graph is a graph in which we can visit from any one vertex to any other vertex. In a
connected graph, at least one edge or path exists between every pair of vertices.

Example
In the above example, we can traverse from any one vertex to any other vertex. It means there
exists at least one path between every pair of vertices therefore, it a connected graph.

There are two ways that we can store the graph or digraph information: an adjacency matrix or an
adjacency list.

An adjacency matrix gives us the ability to quickly access edge information, but if the graph is far from
being a complete graph, there will be many more empty elements in the array than there are full
elements. An adjacency list uses space that is proportional to the number of edges in the graph, but the
time to access edge information may be greater

You might also like