Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you implement public String depthFirstSearch(int startVertex){} ? Method declarations can NOT be changed. No other public interfaces can be added. import java.util.*; public

How do you implement public String depthFirstSearch(int startVertex){} ? Method declarations can NOT be changed. No other public interfaces can be added. import java.util.*; public class MyGraph { private int[][] graph; private int numberOfVertices; /** * @param numberOfVertices number of vertices of the graph */ public MyGraph(int numberOfVertices){ this.numberOfVertices = numberOfVertices; graph = new int[numberOfVertices+1][numberOfVertices+1]; } /** * @param graph The matrix representation on the given graph. Assume column 0 and row 0 are not used */ public MyGraph(int [][] graph){ this.graph = graph; // change any 0 to infinity if the 0 is not on diagonal for(int i = 1; i < graph.length; i++){ for(int j = 1; j < graph.length; j++){ if(i == j) graph[i][j] = 0; else if(i != j && graph[i][j] == 0) graph[i][j] = Integer.MAX_VALUE; } } numberOfVertices = graph.length - 1; } /** * DEPTH-FIRST SEARCH * return a String that represents the vertices in order if the DFS algorithm is used to traversal the graph * starting from the given vertex. If the startVertex not exist, return an error message * @param startVertex The vertex where the traversal starts * @return An ArrayList of Integer that represents the vertices visited in order */ public String depthFirstSearch(int startVertex){ //NEEDS TO BE IMPLEMENTED } }

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

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

Students also viewed these Databases questions

Question

In Problems 91114, solve each equation. 5e 0.2x = 7

Answered: 1 week ago