Showing posts with label backtracking. Show all posts
Showing posts with label backtracking. 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.

Basics of Tree data structure

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