Question A)
Starting from vertex 1, the algorithm will push 3rd and 4th vertex. After that, from vertex 3 the algorithm will push 7th vertex. From vertex 4, vertex 2 and then vertex 8 will be pushed. After that from vertex 7, vertex 5 and then vertex 9 will be pushed. From vertex 2, vertex 6 will be pushed. After that, from adjacent nodes of the vertex 8, there is no vertex left which was not pushed, so the algorithm will go on searching adjacent vertexes of vertex 5. We have same case here, so algorithm will continue finding adjacent vertexes of vertex 9. These vertexes are 10 and 11, so they will be added to queue. Now we have all vertexes visited in order 1 => 3 => 4 => 7 => 2 => 8 => 5 => 9 => 6 => 10 => 11.
Question B)
The biggest distance between 1 and other vertexes is 4. vertex 10 and 11 are at the distance of 4 from vertex 1.
Question C)
comment down for any queries
please give a thumbs up
vector < int > maxDistverticesBFS (int w) for all vertices u num (u) = 0 i 1; i++ num (w dist = 0 1/Second variable is distance from vertex w to current vertex enqueue (w, 0); while queue is now empty dequeue ); answer (v.first) for all vertices adjacent if num (u) is 0 V = = v. second u to v.first i++ (u) num enqueue (u, v.second 1); return answer;
(5 marks) a. The pseudo-code for breadth-first search, modified slightly from Drozdek,1 is as follows: void...
Show the operation of depth-first search (DFS) on the graph of Figure 1 starting from vertex q. Always process vertices in alphabetical order. Show the discovery and finish times for each vertex, and the classification of each edge. (b) A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first search (BFS) tree can also be used to classify the edges reachable from the source of the search into the same four categories....
Consider the following directed graph for each of the problems: 1. Perform a breadth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Show the breadth-first search tree that is generated. 2. Perform a depth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Classify each edge as tree, back or cross edge. Label each vertex with its start and finish time. 3. Remove all the...
from collections import defaultdict # This class represents a directed graph using # adjacency list representation class Graph: # Constructor def __init__(self): # default dictionary to store graph self.graph = defaultdict(list) # function to add an edge to graph def addEdge(self,u,v): self.graph[u].append(v) # Function to print a BFS of graph def BFS(self, s): # Mark all the vertices as not visited visited = [False] * (len(self.graph)) # Create a queue for BFS queue...
You will be implementing a Breadth-First Search (BFS) and a Depth-First Search (DFS) algorithm on a graph stored as an adjacency list. The AdjacencyList class inherits from the Graph class shown below. class Graph { private: vector _distances; vector _previous; public: Graph() { } virtual int vertices() const = 0; virtual int edges() const = 0; virtual int distance(int) const = 0; virtual void bfs(int) const = 0; virtual void dfs(int) const = 0; virtual void display() const = 0;...
(c) Simulate breadth first search on the graph shown in Fig HW2Q1c. You can assume that the starting vertex is 1, and the neighbors of a vertex are examined in increasing numerical order (i.e. if there is a choice between two or more neighbors, we pick the smaller one). You have to show: both the order in which the vertices are visited and the breadth first search tree. No explanations necessary. (d) On the same graph, i.e. the graph in...
Question 3 1 pts Select all of the following that are true: Breadth-First Search only adds each vertex to the queue once. Breadth-First Search generally uses more space compared to Depth-First search. Breadth-First Search may not find the shortest path for an unweighted graph if the graph contains a cycle. At any time during Breadth-First Search, the queue holds at most two distinct dist values from all vertices in
In Python 3 please Apply Breadth First Search (BFS) to traverse the following graph. Start your traversal from vertex 0, and write down the order in which vertices will be visited during the traversal. 1 8 6 7 2 9 5 4 3
7.[6] Consider the graph G below: a.[3] Find a Depth-First Search tree T for the above graph starting with the vertex 0. Show all the vertices as they are discovered in sequence starting from 1 to the last vertex included in T. b.[3] Find a Breadth-First Search tree T for the above graph starting with the vertex 0. Show all the vertices as they are discovered in sequence starting from 1 to the last vertex included in T.
Exam 3 Sample.pdf * ) Q © w E © 112 A n o 99.9% 1. Breadth-first Search a) List out the following graph using adjacency list. Assume the adjacency lists are in sorted order, e.g. when exploring vertex F, the algorithm considers the edge F-B before F-C, F-E, F-H or F-I. b) Run breadth-first-search on the graph below, starting at vertex A. List the vertices in the order in which the vertices are enqueued on the FIFO queue. c)...
1- Give an example (by drawing or by describing) of the following undirected graphs (a) A graph where the degree in each vertex is even and the total number of edges is odd (b) A graph that does not have an eulerian cycle. An eulerian cycle is a cycle where every edge of the graph is visited exactly once. (c) A graph that does not have any cycles and the maximum degree of a node is 2 (minimum degree can...