Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

number 3, no trace is required GRAPH ALGORITHMS 244 1. For the following graphs,

ID: 3715445 • Letter: N

Question

number 3, no trace is required

GRAPH ALGORITHMS 244 1. For the following graphs, give the order that when doing a breadth-first startin e order that the nodes will be EAFor the following g a bread 8.3.4 EXERCISES first traversal starting at the node labelo fr e labeled wi 6 d. will be first vi. at the node labeled with a 1, 2. For the graphs in Exercise 1, give the order that the nodes ited when doing a depth-first traversal starting at the node 3. Write a detailed algorithm for depth-first traversal usi matrix that just prints the node label as the visit operation. You should t it using the graphs in this section to make sure you get the same answer 4. Write a detailed algorithm for breadth-first traversal using an adiad matrix that just prints the node label as the visit operation. You should t it using the graphs in this section to make sure you get the same answ 5. Write a detailed algorithm for depth-first traversal using an adia cency lst that just prints the node label as the visit operation. the graphs in this section to make sure you get the same a You should trace it 6. Write a detailed algorithm for breadth-first traversal using an adjacency her that just prints the node label as the visit operation.You should trace it using the graphs in this section to make sure you get the same answer 7. Prove that each edge in a connected graph will be part of the depth-first traversal tree or will be an edge pointing to a predecessor in the tree. 8. Prove that each edge in a connected graph will be part of the breadth-fis traversal tree or will be an edge pointing to a node in the tree that is neither a predecessor nor a descendent.

Explanation / Answer

Ques 3.

// arr is the adjacency matix

// visited is a boolean matix which tells is the

// node is visited or not, false means not visited

Function depth_first_search(arr , visited , i)

BEGIN

    // display the current node

    print(i);   

    // mark the current node as visited

    visited[i] = true

    // traverse the matrix

    for j = 0 to arr.length()

    BEGIN

         // if the node j is not visited and there is an

         // edge between I and j

         if visited[j] == false and arr[i][j] == 1

         BEGIN

             depth_first_search( arr , visited , j );

         END

    END

END