Showing posts with label topology sort. Show all posts
Showing posts with label topology sort. Show all posts

Sunday, 14 May 2017

Depth First Search in Graph

DFS involves following a path from source vertex to adjacent vertices until there are no other vertex is left to visit.

Objective

  • Start with source vertex, push it into stack, mark it visited and display it
  • Now peek the stack and look for adjacent vertices.
  • If found push it into stack, mark it visited and display it.
  • If not, then pop up from stack and again repeat step 2.
  • Repeat till stack is empty.

Saturday, 13 May 2017

Basics of Graph data structure

  • Graph consist of vertices and edges.
  • They are used to model many realworld examples ( likes cities, network…)


Graph



Implementing a graph with 4 vertices (A,B,C,D) and 4 edges.

Basics of Tree data structure

Tree data structure simulates a  hierarchical tree structure, with root and subtrees represented by linked nodes. Some Terminology Root...