Skip to main content

Graph In Data Structure

      ⇰ GRAPH

A graph is a non-linear data structure. It is a pictorial representation of a set of objects where some pairs of objects are connected by links. It consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are links that connect any two nodes or vertices in the graph. 


Therefore we can say a graph is a collection of nodes and edges in which two nodes are coonected with edges. It can be seen as a cyclic tree, where the vertices maintain any other relationship among them instead of having parent child relationship as in tree. 


Generally a graph 'G' is represented as G(V,E) , where V represents set of vertices of G  and E represents  set of edges or links of G.
following is  a graph with five vertices and seven edges. 
Data Structures Tutorials - Introduction to Graphs
Graph with 5 vertices and 7 edges
We can define the above graph as G(V,E). where V={A, B, C, D, E} and E={ (A,B), (A,C), (A,D), (B,D), (C,D), (B,E), (D,E) }.


    ⇰  APPLICATIONS OF GRAPH :- 
∗  followings are some of most important applications of graph :-


∘ Social networking (Facebook).

∘ Web graphs.
∘ Product recommendation graphs.
∘ Road networks.
∘ Blockchains. 
Bitcoin transaction graphs.
∘ Biological networks.

     ⇰ SOME  BASIC GRAPH TERMINOLOGIES :-

Directed edge :- An edge that is directed from one verted to another.

Undirected edge :- An edge which has no specific direction.

Directed graph :- A graph in which every edge is directed is called directed graph or digraph.

Undirected graph :- A graph in which every edge is undirected is called undirected graph.



Mixed graph:- A graph in which some of the edges are directed and some are undirected is called mixced graph.

Null graph :- A graph containing only isolated vertex or a graph without an edge is called null graph. 

Path :-The sequence of nodes that are followed in order to reach some terminal node is called path.

Closed Path :- If the initial node is same as terminal node then it is called as closed node.

Simple Path :- If all the nodes of the graph are distinct then such path P is called as simple path.

Cycle :- The path which has no repeated edges or vertices except the first and last vertices is called cycle.

Connected Graph :- A graph in which some or any path exists between every two vertices is called connected graph.

Complete Graph :- A graph in which  every node is connected with all other nodes present is called complete graph. 

Weighted Graph :- A graph in which each edge is assigned with some data such as length or weight is called weighted graph.

Degree of the Node :- A degree of a node is the number of edges that are connected with that node. A node with degree 0 is called as isolated node.

       REPRESENTATION OF GRAPH :-
∗ There are many ways of representation of graph in memory. Some of them are as follows :-
   i >  Adjacency matrix representation.
  ii > Incidence matrix representation.
  iii > Adjacency List representation.
  iv >  Edge list representation.

 i >  Adjacency matrix representation :-  Adjacency matrix is a type of sequential representation of graph . It is used to represent which nodes are adjacent to other. We can represent a graph using matrix. The given matrix is square adjacency matrix. It contain  binary 1 ,if there is an edge in ith row to jth column. When we will try to represent an undirected graph using adjacency matrix, the matrix will be symmetric.
Representation of Graphs: Adjacency Matrix and Adjacency List ...
For undirected graph

Representation of Graphs: Adjacency Matrix and Adjacency List ...
For directed graph




ii > Incidence matrix representation :-  Incidence matrix representation is also a graph epresentation. In this representation  graph can be represented using a matrix of size, total number of vertices by total number of edges.

It means if a graph has 5 vertices and 6 edges, then it can be represented by matrix of 5X6. In this matrix, columns represent edges and rows represent vertices. This matrix is filled with either 0 or 1 or -1. Where, 0 is used to represent row edge which is not connected to column vertex. 1 is used to represent row edge which is connected as outgoing edge to column vertex. -1 is used to represent row edge which is connected as incoming edge to column vertex.
Data Structures Tutorials-Graph Representations|Adjacency ...
Incidence matrix representation




iii > Adjacency List representation :- The adjacency list representation is a type of graph representation .This representation is based on Linked List. In this approach, each Node is holding a list of Nodes, which are Directly connected with that vertices. At the end of list, each node is connected with the null values to show  that it is the end node of that list.This representation can also be used to represent a weighted graph. The weights of edges can be represented as lists of pairs. 

A directed graph represented by adjacency lists. | Download ...
Adjacency list representation of directed graph
GATE2016-2-41 - GATE Overflow
Adjacency list representation of undirected graph





iv >  Edge list representation :- In this graph representation we have to use  using one dimensional array . This is called the edge list. In this representation for each edge the first element is the source and the second one is the destination. For undirected graph representation the number of elements in the edge list will be doubled.
Graph Representation: Edges and Vertices List - Lets Code Them Up!
Edge list representation



click here for Basic concept of Tree

Share, Follow and please comment if you find anything incorrect, or to share more information about the topic discussed above.

Comments

Popular posts from this blog

Process Scheduling And Types of Process Schedular :-

        ⇰ PROCESS SCHEDULING Process Scheduling  is a task  of Operating System that schedules processes of different states like new, ready, waiting, terminated  and running.This scheduling helps in allocation of CPU time for each process, and Operating System allocates the CPU time for each procss. And the process scheduling plays important role to keep the CPU busy all the time.  ⏩   Followings are some objectives of Process Scheduling :-  i > To increase the amount of users within acceptable response times.  ii > To maintain the balance between response and utilization of system. iii > To decrease the enforce priorities and  give reference to the processes holding the key resources.      ⇰  PROCESS SCHEDULAR A scheduler carries out the pro cess scheduling work. Schedulers are often implemented so they keep all computer resources busy and  allows multiple users to share system resources  to achieve  multiprogramming .  There are  mainy three types of pro

Process & Its state And process control block :-

                ⇰  PROCESS :- A process can be thought of as a program in execution. Means when any program is executed it becomes process. A processwill need certain resources such as CPU time , memory, files and I/O devices to complete its task. These resources are allocated to the process either when it is created or at the time of execution.             A process is the unit of work in most systems. A system consistes of a collection of processes. All these processes may execute concurrently. Traditionally a process contained only a single thread. Most modern operating ststems now supports processes that have multiple threads.         The operating system is responsible for several important works of process management as - the creation and deletion of process, the schrduling of process, communication and deadlock handling of process. Process is broudly divided into two types:-  i> System  Process. ii> User Process. Early computers allowed only one program be ex

Semaphores In Process Synchronization

   ⇰  Semaphores :-   Semaphore is actually a method or tool to prevent race condition. Race condition can cause loss of data or even deadlock situation. For prevention from these conditions, the semaphore is one of the method.  Semaphore was proposed by Dijkstra in 1965. Simaphore    is a very significant technique to manage concurrent processes.  Semaphore is useful tool in the prevention of race condition. But the use of semaphore never means a guarantee that a program is free from these problems.     Semaphore is an integer variable which is used in mutual exclusive manner by various concurrent cooperative processes in order to acheive synchronization. Hence semaphore is one of the way to achieve synchronization.  Semaphore is basically  a variable which is non-negative and shared between threads. This variable is used to solve the critical section problem and to achieve process synchronization in the multiprocessing environment. Semaphore contains some operations as f