Question: Program 1 : Perform BFS ( Breadth - First Search ) and output the heights of each tree in the search forest. In both problems

Program 1: Perform BFS (Breadth-First Search) and output the heights of each tree in the search forest.
In both problems you will read a sequence of adjacency lists. Here we assume the lists are sorted to get well-defined answers. If your traversal algorithm needs to make a choice, then choose the first (lowest index) vertex available. Here, the first line for each digraph is an integer n indicating the order of the digraph. This is followed by n white space separated lists of (out-) adjacencies for nodes labeled 0 to n 1. The last digraph of the sequence will be a digraph of order 0 and this is noi processed, Input comes from stdin (keyboard) and output goes to stdout
(console).
The question is to write a python code that does the following. The code gets gets it input through sys.stdin.
Example inputs and outputs given below:
Sample Input/Output
Adjacency Lists
3
1
2
01
5
13
024
3
014
23
8
123
0
07
12
23
6
015
14
0
BFS Sample Output
2
2
31

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!