Find a path from a source vertex to the destination vertex

Assignment Help JAVA Programming
Reference no: EM131482922

Depth First Search Assignment

Overview

Imagine it's the first day of classes and you're trying to find your way around the science building to SB 100. You're trying to make it to lecture on time so that your absolutely terrifying professor doesn't humiliate you in front of the entire class for being late. But you're lost! Corridors double back on themselves. The third floor of Remsen connects to the second floor of the science building. You decide to follow the corridor and it somehow leads you to the floor above though you have no memory of climbing stairs. You're running out of food and water. If only you knew how to get to the science building cafe!

In this totally plausible scenario, what do you do? You could strike out in random directions, bouncing off walls until you're lucky enough to get out and see your family again. Or you could be strategic. Pick a path. follow it until it either doubles back or reaches your destination. Do this with every possible path and, maybe by the end of the semester, you'll know a path to your lecture! Alternatively, you could use a computer to solve the maze for you, and have it show you the path to take.

Design

1. The goal of assignment 2 is to solve the maze, using depth-first search. Since this is a continuation of assignment 1, your solution must build on your own code from assignment 1. You are welcome to fix bugs in assignment 1 for this assignment. but only the code that is specific to assignment 2 is graded.

Your goal is to find the first possible path from the first room in the maze (rooms[0] ) to the last one if n is the number of rOOMS then rooms[n-1]) by applying the depth-first search algorithm. The depth-first search algorithm uses recursion (recursive calls) to find the solution. For a graph, since it can have cycles, the depth-first search algorithm employs a Boolean array visited to keep track of the visited status (visited or unvisited) of each vertex in the graph. Initially_ all vertices are unvisited

Depth-First Search Algorithm (DFS):

1. Find a path from a source vertex to the destination vertex in a graph.

2. Start the search by making the current vertex the source vertex.

3. Determine if the current vertex leads to the destination vertex:

a. Mark the current vertex as visited.
b. For each of the current vertex's outgoing edges, check the visited status of the edge's adjacent vertex.
c. If the adjacent vertex is visited then move on to the next adjacent vertex.
d. If the adjacent vertex is unvisited then determine if there is a path from the adjacent vertex to destination vertex by recursively carrying out step 3 with the adjacent vertex being the current vertex in the recursive call to depth-first search.

4. Once the depth-first search algorithm reaches the destination vertex it adds it to the solution path, and then recursively adds all the vertices on the direct path back to the source vertex.

This is the basic template for the depth-first search algorithm. You can use it as the basic starting point to write your version of the dfs method to find the first possible path from the first room to the last room in the maze.

dfs (Vertex s, Boolean visited)
visited[s] = true;
for each Vertex v adjacent to s if (!visited[w]) dfs(w);

2. Add the following line of code to add the data member pathSolution to the Maze class: private DoublyLinkedList<Vertex> pathSolution;
Place the above declaration of pathSolution in the Maze class right below the line of code: private Vertex[] rooms;

3. You will write the public method findPath in the Maze class. This method should find the maze's solution the first time it is called, using the depth-first search algorithm described above, and stores the resulting linked list in the data member pathSolution. If there is no solution then pathSolution should store null. The idea is to compute the solution only once, and remember it. If findPath is called twice, the second time it is called it just returns the solution remembered. In addition to finding or remembering the path solution, the findPath method should print the path.

4. You will write the private method dfs in the Maze which has the three parameters: 1) the index of a starting vertex, 2) the index of an end vertex, and 3) the boolean array visited, and returns a path from the starting vertex to the ending vertex and null if it can't find a path to the end vertex.

5. The method findPath creates and initializes the Boolean array visited and starts the actual search by calling the method dfs with the Maze's first vertex (rooms[O]) as the start vertex, and the last vertex (rooms[n-1]) as the end vertex.

6. If needed. you can write additional methods to help in your implementation of findPath and dfs but they must be defined as private. Methods should be reasonably small following the guidance that "A function should do one thing, and do it well."
Create a driver class and make the name of the driver class Assignment2 and it should only contain only one method:
public static void main (String args[1].

The main method will receive the name of the maze file via a command line argument. For example, the command to run the program to process the maze file sample.niaze is:

java Assignment sample.maze

The main method will create an instance of a Maze object passing the filename into the Maze object's constructor. Then. the main method will call the findPath method twice.

8. Do NOT use your own packages in your program. If you see the keyword package on the top line of any of your .java files then you created a package. Create every .java file in the src folder of your Eclipse project

9. Do NOT use any 2:raphical user interface code in your program!

10. Document and comment your code thoroughly.

The total project is worth 15 points, broken down as follows:

If the program does not compile successfully then the grade for the assignment is zero.

If the program compiles successfully then the grade is computed as follows:

Proper submission instructions:

1. Was the file submitted a zip file.

2. The zip file has the correct filename.

3. The contents of the zip file are in the correct format.

Follow all coding instructions (each item is worth 2 point):

4. The driver file has the correct filename, AssignmentIjava?

5. The driver file contains the method main performing the exact tasks as described in the assignment description?

6. The Maze class contains the method dfs performing the exact tasks as described in the assignment description?

The Maze class contains the method findPath performing the exact tasks as described in the assignment description?

Program execution (each item is worth 2 point):

8. The program executes without any errors?

9. The program. produces the correct output?

Attachment:- Java_Assignment.zip

Reference no: EM131482922

Questions Cloud

What is the cost of equity from retained earnings : You have been provided with the following data: risk free rate= 5.0%; market return = 12.0%; and beta = 1.3. What is the cost of equity from retained earnings?
Define gross private domestic investment : Gross private domestic investment (GPDI) includes new residential construction as investment. Why is new housing included? Isn't this just another consumer.
What is glassmakers pre-merger wacc : The risk free rate is 6%. The levered beta is 1.36. The equity risk premium is 4%. What is Glassmakers' pre-merger WACC?
What are some of the limitations of the national income : What are some of the limitations of the national income accounts in how they represent our standard of living?
Find a path from a source vertex to the destination vertex : Find a path from a source vertex to the destination vertex in a graph. Start the search by making the current vertex the source vertex.
Compute gdp and national income : Using the data below, compute GDP, national income, and NNP.
Develop the ability to work independently : Develop the ability to work independently and contribute as a member of team employing appropriate interpersonal, professional and technical communication skills.
Develop a process map about the prescription filling process : evelop a process map about the prescription filling process for HMO's pharmacy, in which you specify the key problems that the HMO's .
Write an evaluation essay supported by sources : FFE002 Writing Assignment - Academic Essay. To write an evaluation essay supported by sources. Climate change is having a significant impact on coastal areas

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd