Backtracking algorithm

Assignment Help Data Structure & Algorithms
Reference no: EM131369516

Assignment

In this question, you will test, using a backtracking algorithm, if a mouse can escape from a rectangular maze.

The backtracking algorithm helps the mouse by systematically trying all the routes through the maze until it either finds the exit or exhausts all possible routes (and concludes that the mouse is trapped in the maze). If the backtracking algorithm finds a dead end, it retraces its path until it reaches a position from which there is an untried path. The backtracking algorithm always tries all directions from any position, and always in the same order.

The input to the algorithm is a maze with walls (represented by '1' characters) and open passage ways (represented by '0' characters). The starting position of the mouse is represented by 'm' and the exit from the maze by 'e'. Your program should read the maze in from a file, and the name of the file should be a command-line argument. The first line of the input will contain the number of rows and the number of columns in a maze. Thus, the input might look like the following:

6

5

 

1

1

1

1

1

1

0

0

e

1

1

1

1

0

1

1

m

1

0

1

1

0

0

0

1

1

1

1

1

1

The maze will always have a wall around the outside, so you need not be concerned about the mouse falling off the maze as it explores all directions.

The backtracking algorithm keeps a stack of positions that are the beginnings of paths it has yet to try. From the current position, the algorithm pushes onto the stack any untried open neighboring positions (if there are any), always looking forward, backward, left and right from the current position. At each step, the algorithm pops the top position off the stack and pushes the untried neighboring positions onto the stack. The algorithm must mark each visited position with a period to avoid revisiting positions --- so that it will not loop forever trying the same routes.

The backtracking algorithm works as follows:

Because the backtracking algorithm needs a stack, you should implement a stack class (or you can use that from COSC 2006). Each item in the stack is the position of a cell in the maze --- that is, the row and column number of the cell.

Your program should print out the maze after each cell is visited, showing which cells have already been visited. Finally, your program must print out a message indicating whether the exit was found or that no route to the exit could be found (the mouse is trapped).

To develop your program, you can use the input file testMaze.txt, which contains the above maze.

Attachment:- MazeTest.txt

Verified Expert

In this assignment we need to find a way for mouse to reach from source to goal destination .This assignment was about backtracking in two dimensional array .given algorithm is not optimize we can use A* algorithm to solve this problem much faster.

Reference no: EM131369516

Questions Cloud

Computer is able to check the entire population of pencils : New computerized systems are able to check for defects on products right on the assembly line. For example: a pencil manufacturer is able to use laser scanning to check for the size of the pencils. Since the computer is able to check the entire popul..
Inventories and inventory management : Inventories - and inventory management - should be a thing of the past. An efficient and effective organization should be able to employ lean and just-in-time concepts so that inventories are not necessary. Do you agree or disagree with this statemen..
What organizing to implement vertical integration means : Please explain in detail what "Organizing to implement vertical integration" means and how it involves organizational structure, management controls and compensation policies.
Dictum of management theory : It has long been a dictum of management theory that leaders must adapt their behavior to fit the specifics of a situation. Discuss whether transformational leadership is appropriate for all occasions. In which situations might it not be effective and..
Backtracking algorithm : COSC 2007 -Data Structures - The backtracking algorithm helps the mouse by systematically trying all the routes through the maze until it either finds the exit or exhausts all possible routes
What are difference between discrete and continuous variable : qnt 275-What are the differences between quantitative and qualitative variables? What are the differences between discrete and continuous variables.
What is the probability : Assume that 2% invest in both kinds. If an investor is chosen at random, what is the probability that this investor has either public or corporate funds?
What will be the price level of the overall economy : ECON 3123- Suppose that the economy consists of two types of firms. Flexible price firms, who set prices P + a(Y - Y¯), and sticky price firms, who set prices E(P). Fraction s of the firm population is sticky. What will be the price level of the o..
Probability that randomly chosen user could not use a device : If there were 18 million users of handheld data devices of this kind on that day, what is the probability that a randomly chosen user could not use a device?

Reviews

inf1369516

2/6/2017 5:27:17 AM

Sorry for last email. You have a great job, I was simply getting somewhat stressed. Why I have no clue! This is effectively my fifth or sixth paper from all of you and they have been only extraordinary. This proposition is great done. Expert did awesome.

inf1369516

2/6/2017 5:26:13 AM

Could you please make a discount for me? I have done many orders with you, and also I have more assignments this semester I will order from you guys. I would like to ask you about the output, it seems to me in each step the position is not changing , is it correct output , or it has to be changing in each step ? Also, please make a full comments for the program to understand the code, last thing, Did you use The backtracking algorithm that provided in the question file ? thank you..

len1369516

1/24/2017 3:34:07 AM

a basic java program that should be using a stack class all details is in the file attached In this question, you will test, using a backtracking algorithm, if a mouse can escape from a rectangular maze. Your program should print out the maze after each cell is visited, showing which cells have already been visited. Finally, your program must print out a message indicating whether the exit was found or that no route to the exit could be found (the mouse is trapped).

Write a Review

Data Structure & Algorithms Questions & Answers

  Uml graphical notation to define the object classes

Use UML graphical notation, construct the design for the system to define the object classes and show the interaction of the data collection sub systems.

  Creating an object oriented data model

Create an object oriented data model, including all appropriate notations, to represent the given situation. In a particular region there are a number of gardens.

  What are the properties of an algorithm

What is a first-in-first-out data structure ? Write algorithms to perform the following operations on it - create, insertion, deletion, for testing overflow and empty conditions.

  Apply algorithm on string to make substrings

For instance, applying algorithm on string 37540 must make the following substrings (not necessarily in this order): 0; 3; 75; 54; 375; 540.

  Polynomial time algorithm for rooted directed acyclic graphs

Illustrate that if you were given a polynomial time algorithm for determining whether two rooted directed acyclic graphs are isomorphic, then polynomial time algorithm for testing.

  Identifying the location of rubric objectives

Code Comments are used to identify the location of rubric objectives, Code Formatting is used to raise the readability of the HTML Code.

  Block diagram for medical center of devry ed system

Block Diagram for Medical Center of DeVry ED System-When a patient arrives at the ED (emergency department) of the Medical Center of DeVry, demographic and insurance information is obtained

  Efficient algorithm to achieve goal using few base stations

Certain points along the road, so that every house is within four miles of one of the base stations. Give an efficient algorithm that achieves this goal using as few base stations as possible.

  What is the running time of the algorithm that creates tree

What is the running time of the algorithm that creates the tree? where the measure of the size of the program is the number of rows (n|) and the number of bytes (k|) in the key.

  Describe algorithm that finds maximum feasible flow in graph

Describe an algorithm that finds a maximum feasible flow in G. Denote by MF(|V|, |E|) the worst-case running time of an ordinary maximum flow algorithm.

  Decrypting the ciphertext to recover the plaintext

If you get ciphertext message YPHDCRPBEQTAA, decrypt to recover plaintext.

  Efficient algorithm that achieves goal using base station

So that every house is within four miles of one of the base stations. Write efficient algorithm that achieves this goal, using as few base stations as possible.

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