Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. In algorithm BFS on Homework 1, we made use of the variable dj, to denote the distance of node j from the initial node

image text in transcribed
1. In algorithm BFS on Homework 1, we made use of the variable dj, to denote the distance of node j from the initial node i. Now, we will define a new variable nj for every node j in the graph, whose values will be computed in a modified algorithm BFS, starting from node i, as follows (we will show also the computation of d at the same time): o If dioo, then o Elself dh-d + 1, then For the initial node i, we set ni to 1. Notice that the computation of d has not changed, but we repeat it here since its value is used in determining the value of n. Write a revised function bfs(g, startnode) that takes the same input and does the same computations as the original BFS algorithm, the added steps to compute n, as given by the steps above. The function should return a tuple that contains d and n, where the first element was returned by BFS (the version for computing distances) from Homework 1, and n is the new variable. 2. Running bfs from Part 1 on graph gi in Figure 2, starting from node 0, report the values dy and nj for every node j in gi. What quantity does the value of nj, for a node j, reflect? 0 2 3 6 Figure 2. Graph gi for Part 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions