Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 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

Java, Programming

  • Category:- Java
  • Reference No.:- M92291658

Have any Question?


Related Questions in Java

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As