Depth first search and breadth first search, Data Structure & Algorithms

Assignment Help:

Q. Illustrate the result of running BFS and DFS on the directed graph given below using vertex 3 as source.  Show the status of the data structure used at each and every stage.  

1844_DFS and BFS.png

 

Ans:

Depth first search (DFS):

917_DFS.png

 

Depth first search (DFS) beginning from vertex 3 as source and traversing above adjacency list one by one, the following result is obtained:

3-7-2-8-6-5-4-1

 Breadth First Search(BFS):

348_BFS.png

In this elements are inserted from rear and deleted from front. Before removing an element, insert its element in the queue. So result get of BFS in the given graph is:

3-7-2-8-6-5-4-1


Related Discussions:- Depth first search and breadth first search

Compound interest, Write the algorithm for compound interest

Write the algorithm for compound interest

State cmy model, CMY Model  The cyan, magenta, yellow (CMY) colour mode...

CMY Model  The cyan, magenta, yellow (CMY) colour model is a subtractive model based on the colour absorption properties of paints and inks. As such it has become the standard

Array and two-dimensional array, Q. Describe the term array.  How do we rep...

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.

Write down any four applications of queues, Write down any four application...

Write down any four applications of queues.            Application of Queue (i)  Queue is used in time sharing system in which programs with the similar priority form a queu

Graph with n vertices will absolutely have a parallel edge, A graph with n ...

A graph with n vertices will absolutely have a parallel edge or self loop if the total number of edges is greater than n-1

What are the properties of colour, Properties of colour Colour descript...

Properties of colour Colour descriptions and specifications generally include three properties: hue; saturation and brightness. Hue associates a colour with some position in th

Hasing and indexing, differentiate between indexing and hashing in file org...

differentiate between indexing and hashing in file organization

Recursion, difference between recursion and iteration

difference between recursion and iteration

Abstract data types, Abstract Data Types :- A useful tool for specifying th...

Abstract Data Types :- A useful tool for specifying the logical properties of a data type is the abstract data type or ADT. The term "abstract data type" refers to the basic mathem

Design a framework of a genetic algorithm, You have to design a framework o...

You have to design a framework of a Genetic Algorithm (GA) with basic functionality. The basic functionality includes representation, recombination operators, tness function and se

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd