Introduction to Graph Data Structure

What is a Graph?

Graph is a non linear data structure, it is very useful for navigational purpose in real life.

Undirected Graph – It is a set of nodes and a set of links between the nodes. Each node is called a vertex, each link is called an edge, and each edge connects two vertices.

Introduction to Graph Data Structure

Vertices are {1, 2, 3, 4, 5}

Edges are {(1,2), (2,3), (3,4), (4,5), (5,1), (2,1), (3,2), (4,3), (5,4), (1,5)}

Directed Graph – It is a set of vertices and a collection of directed edges that each connects an ordered pair of vertices. In this one vertix points to other and so on.

Vertices are {1, 2, 3, 4, 5}

Edges are {(2,1), (3,2), (4,3), (5,4), (1,5)}

Graph Data Structure

VertexIn-DegreeOut-Degree
111
211
311
411
511

Indegree of vertex is the number of edges which are coming into the vertex, While out-degree is the number of edges are going out of the vertex.

Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment