Question
This is a programming assignment. Submit all your results in pdf files. Implement the breadth-first search algorithm described on page 18 of the lecture notes
This is a programming assignment. Submit all your results in pdf files.\
Implement the breadth-first search algorithm described on page 18 of the lecture notes on Graphs, with the graph represented as an adjacency matrix A of size n by n, where n is the number of nodes. Your code should print out all nodes in L. The algorithm is O(n). a. Submit the pseudo-code of the algorithm. If your solution in homework 2 is correct, you may use it here. b. Implement the algorithm in actual code with appropriate comments. You may use any programming language in your implementation. Submit your actual code. Input: nNode, sID, filename nNode is the number of nodes. SID is the source node ID, an integer in the range [1, nNode). "filename is the name of a text file containing an nNode by nNode array of 0 and 1 values, representing the adjacency matrix of a graph. Its first row and first column are for node 1; Its second row and second column are for node 2; and so on. Output or printout: nodes in each Li, all_time all_time is the execution time in milliseconds of your whole program, including file reading time. 2. (12 points) Run your program on the following 4 test cases. graph1.txt and graph2.txt are provided to you. Submit the required outputs. Searching the input graph lwith node 1 as the source node
: (14, 1, graph1.txt) Searching the input graph 1 with node 10 as the source node: (14, 10, graph1.txt) Searching the input graph 2 with node 1 as the source node: (30, 1, graph2.txt) Searching the input graph 2 with node 10 as the source node: (30, 10, graph2.txt) . Given an adjacency matrix A of size n by n, where n is the number of nodes and s is the source node. BFS (A, n, s) visited = a vector of size n with value "False" nextLayer = [s] currentLayer = [] num = 0 visited[s] = True while nextLay is not empty currentLayer = nextLayer nextLayer = 1) Print (num) num = num + 1 For index in range (length of currentLayer) currentNode = cur[index] print(currentNode) for (i,i,>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started