Simple GUI Notepad Using Ruby

GUI Notepad Using Ruby Code require 'tk' class Notepad def saveFile file = File.open("note", "w") ...

Showing posts with label Differences. Show all posts
Showing posts with label Differences. Show all posts

Friday, February 6, 2015

Difference Between BFS and DFS

Based OnBreadth First Search (BFS)Depth First Search (DFS)
Description Of The AlgorithmBreadth first search (aka. BFS) is a searching method
used to search (or. explore) for a node (or the entire
structure) by traversing from root node and explore the
search in level by level.
Depth first search (aka. DFS) is a searching method
used to search (or explore) for a node (or the entire
structure) by traversing from root node and explore the
search as deep as possible until a dead end is found.
Data Structure UsedBreadth first search uses a Queue.Depth first search uses a Stack.
Similar ToBreadth first search is similar to level-order traversal.Depth first search is similar to pre-order traversal.
SpeedBFS is slower than DFS.DFS is more faster than BFS.
AdvantageBreadth first search always finds a shortest path from the
start vertex to any other for unweighted graphs.
Depth first search may not finds a shortest path.
Algorithm TypeA greedy algorithm. (update neighbors of closest nodes first).A backtracking algorithm (explore one path until dead end).
Time & Space ComplexityBFS takes O(bd) time and O(bd) spaceDFS takes O(bh) time and O(h) space
Applications
  • Finding the shortest path.
  • Testing for bipartiteness.
  • In spanning tree.
  • Web crawler.

  • Topological sorting
  • Finding the bridges of a graph.
  • Maze generation.
  • Finding strongly connected components.
Traversal Example

8, 3, 10, 1, 6, 14, 4, 7, 3


3, 1, 6, 4, 7, 10, 14, 13