Nishita
2 min readNov 22, 2019

Graphs in data structure

Graphs is A non- linear data structure. It’s a non cycle. It’s consisting of nodes(vertices) and edges. Graphs are used to solve real life problem .

Graphs are two types in data structure.

  1. Directed
  2. Indirect

Directed graphs : Directed graphs contains an ordered pair of nodes(vertices). It’s called a directed graph. The edges of the graph represent a specific direction from one vertex to another. The vertex is represent an arrow(->) .

Indirect graph : Indirect graph contains an unordered pair of vertexes, it’s an indirect graph. In other words, there is no specific direction to represent the edges. The vertexes connect together by undirected acrs, which are edges without arrow.

Minimum cost spaning trees:-

A spanning tree of a graph is just a sub- graph that contains all vertices and is a tree ( with no cycle). A graph may have many spanning trees.

There are two types(Alogrtim) of mcst:-

  1. Prim’s algorithm
  2. Kruskal’s algorithm

Prim’s algorithm:

  • Prim’s algorithm initializes with a node ( Vertixes).
  • Prim’s algorithm span from one node to another node.
  • Prim’s algorithm operates on two disjoint sets of edges in the graph.

Kruskal’s algorithm:

  • Kruskal’s alogrtim initialize with an edge.

Kruskal’s alogrtim operates on a single set of edges in a graph.

Another types of graph:

Dijkstra’s algorithm:

  • Dijkstra’s algorithm named after it’s discovered, Dutch computer scientist E. W. Dijkstra’s. Sloves the problem box finding the shortest path from a point in a graph to a destination with non - negative edge.
  • It’s turns out that can find the shortest paths from a given source to all vertices in a graph in the same time.
  • Dijkstra’s algorithm finds a shortest path between all pairs of vertices in a graph.