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

  Explain in words a divide-and- conquer algorithm

explain in words a divide-and- conquer algorithm that runs in O(log n) time, and that determines if there is an i for which a[i] = i. Argue that your algorithm is correct and provide supporting pseudo-cod

  Explain computer algorithms and its significance

Explain computer algorithms and its significance. Explain some of the technologies that have contributed to the exponential growth of the Internet and the World Wide Web (WWW).

  Describe ambiguity in proposed algorithm

Describe the distinction between an ambiguity in a proposed algorithm and an ambiguity in the representation of an algorithm. Describe how the use of primitives helps remove ambiguities in an algorithm's representation.

  Write algorithm so that it only works with primitive data

Your algorithm must use Comparable objects. Do not write the algorithm so that it only works with primitive data values such as int or double.

  Placing 8 pieces (the queens) on an 8 by 8 chess board.

I want help with writing the opeartors and states includiing its precondition and action for the eight queens problem where the queens must not be in conflict. that is placing 8 pieces (the queens) on an 8 by 8 chess board.

  Explaining instruction format of operation code field

Operation code field, a mode field, to specify one of seven addressing modes, a register address field to specify one of 60 processor registers, and memory address. Specify instruction format and number of bits in each field if the instruction ..

  Discuss why it is necessary to balance binary search trees

Discuss why it is necessary to balance Binary Search Trees (BSTs). Calculate the Average Comparison Effort (ACE) value of the BST.

  Data systems and design

Suppose if you have a program with a housekeep() module, a mainloop() module, and a finishup() module, when is the second input record usually read?

  Identify the advantages of using terminal services

Compare and contrast the Terminal Services model to the mainframe / terminals and client / server models. Consider security, licensing, bandwidth, and network traffic. Decide which model you believe is the best and describe why.

  Survey of fault tolerance policy for load balancing scheme o

This paper investigates about fault-tolerance in load balancing schemes in distributed environment. There are some more parameters influencing QOS but our main focus is on fault tolerance and load balancing.

  Write a recursive solution to towers of hanoi problem

Write a recursive solution to Towers of Hanoi problem - This child''s toy is actually an example of a classic mathematical puzzle called the Towers of Hanoi problem.

  State two different self-reductions for the sum problem

State two different self-reductions for the SUM problem and give recursive algorithms based on your divide-and-conquer self-reductions to solve the SUM problem.

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