COMP2230 Algorithms Assignment

Assignment Help Data Structure & Algorithms
Reference no: EM133006890

COMP2230 Algorithms - The University of Newcastle

Problem Overview

This assignment can be done individually or in pairs and it involves performing two or four tasks, respectively.

1. Write a program that generates a random maze of a requested size.
2. Write a program that implements DFS technique for solving a maze.
3. Pairs only: Write a program that implements BFS technique for solving a maze.
4. Pairs only: Compare and contrast the two techniques on the basis of program running time, and the number of ‘steps' taken to solve the maze.

We will now look at how to define our maze, before describing each task in more detail.

Maze Definition

Your aim is to create a simple maze that will have exactly one path from any point in the maze to any other point (as an example, see Figure 1). Therefore, your maze will not have inaccessible areas (cells without any missing walls around them), open areas (cells without walls), and no circular paths (loops).

1746_figure.jpg

Figure 1 - sample maze

We can represent our maze as a 2D array (matrix) of Cells. Each Cell knows which of the four possible walls are adjacent to it. Each cell also knows if it is a starting or finishing cell. For example, in the maze shown in Figure 1, the top left hand corner cell (start) has walls to the top, left and right, but no wall below it, so we would be able to move from this cell to the cell below in a valid move. This cell would also have a flag to indicate that it is the starting cell. The maze in Figure 1 is a 4x4 maze with 16 cells.

We can simplify the above cell representation somewhat, such that, instead of a cell needing to know about the four directions around it each cell only needs to know if you can move to the cell to the right or to the cell down from it. This requires only 2 bits of information: Both closed (0) Right only open (1) Down only open (2) Both open (3). So our top left hand corner cell can be represented by the value 2 since we can only move down, and not to the right.

When we need to know about connectivity to cells above or to the left of us, we just need to look at their information. For instance, if I want to know about paths out of the cell in position 6 of the above maze (marked with an X) I know directly how it can move to the right or below. The data for this cell is 0 indicating it can't move to the right or down. To find if it can move to the top, I look at the data for cell 2 (the cell above it), which has value 3 indicating I can move both right and down from this cell. This also tells me that I can move up from cell 6. Similarly, I look to the value of cell to the left to know if I can move left from the current cell.

1. Generating a Random Maze

Although there are many techniques for generating mazes, we will focus on only one technique in this assignment. We will use a Depth First Search (DFS) technique to generate a random maze. The technique is as follows. To generate an n×m maze we create a grid graph of size n×m (for example, see Figure 2 for a 5x5 grid).

2374_figure1.jpg

Figure 2 - sample 5x5 grid

To generate the maze, we mark a random vertex (vertex 1 in the top left corner in this example) as the start node, and then perform a DFS on the graph. When selecting which vertex to visit from the current node, we randomly select an unvisited node from the neighbouring vertices. For each edge that appears in our DFS tree, we consider this as a way to move from one cell to another in our resulting maze. Formulated another way, when two nodes are not connected by an edge in the DFS tree, then there is a wall between these two cells in the resulting maze. See Figure 3 for a sample DFS tree and resulting maze. Here the vertex labels indicate the order in which the nodes were visited in the DFS. The node that is the last one ‘visited' in our DFS is marked as the finish node (e.g., vertex 25, cell 3 in Figure 3).

1934_figure2.jpg

Figure 3 - sample maze generation

Your MazeGenerator program should ask the user for the size of the maze, based on the number of columns and rows and a file name for output. It should randomly generate a maze of this size. It will set the randomly visited first node as the start node, and the last node visited in the DFS as the finish node. Once the maze is generated, your program should save the maze to a file in the following format.

n,m:start_node:end_node:cell_openness_list

where
• start_node and end_node are not equal and are between 1 and n×m
• cell_openness values are decided by the following codes. 0: Both closed
1: Right only open 2: Down only open 3: both open

Example file format for the sample maze shown in Figure 3 would be:

5,5:1:3:1223030112231122230210110

2. Solving a Maze with DFS

Your second program MazeSolverDFS will input a maze from a file given as a command line argument in the format discussed above and solve it using a DFS. When solving a maze your program needs to keep track of order in which it visits the cells, and the numbers of steps taken to ‘walk' from start to finish. It will also keep track of the time taken to solve the maze. When selecting the next cell to visit, your program should always select the cell with the lowest grid number, as shown in Figure 2.

The program should output:
• The solution to the maze (path from start to finish). For example, looking at the path in Figure 4, the cell ordering is (1,2,7,6,11,16,21,22,17,12,13,14,15,10,9,4,5,4,9,8,3)
• The number of steps in this path. (For example, the number of steps is 20 for path given above). A step is a move from one cell to the next. Note that the sample solution contains a loop which is when a wrong path was taken, and we need to backtrack to then find the end point.
• The time taken to solve the maze, in milliseconds.

59_figure3.jpg

Figure 4 - sample maze solution path

3. Pairs only: Solving a Maze with BFS
If you are doing the assignment in pairs, your third program MazeSolverBFS will input a maze in the format discussed above and solve it using a BFS. Your program should produce the same output as for Task 2, that is:

• the solution to the maze from start to finish;
• the number of steps taken to find the finish;
• the time taken to solve the maze, in milliseconds.

4. Pairs only: Comparing the Two Techniques
To compare your two techniques for solving a maze, please produce the following data. Generate 5 random mazes for each of the following grid sizes.
• 20x20
• 20x50
• 100x100
For each maze you should also include maze.dat file containing the description of the maze in the format n,m:start_node:end_node:cell_openness_list.

Generate a table that compares the number of steps and time outputs, for each set of mazes, and for each method. Based on this data, write a very brief (50 words max) analysis of your results. That is, which method do you think performs better, and why?

Reference no: EM133006890

Questions Cloud

Estimate of the supply of people : In the meeting of the Company Senior Management, Finance Director alluded to the following statement, 'human resource forecast is a determination of the demand
Important principles and issues in setting the wage system : What do employers wish to achieve by the system of wages for workers of an enterprise? Outline the important principles and issues in setting the wage system.
What are the roles and responsibilities of the parties : What are the roles and responsibilities of the parties to the disputes? What are the advantages and disadvantages of each procedure?
Despite the extensive measures : Despite the extensive measures put in place by businesses, COVID-19 has substantially affected the operations of corporations.
COMP2230 Algorithms Assignment : COMP2230 Algorithms Assignment Help and Solution, The University of Newcastle - Assessment Writing Service
Explain how does nutrition relate to the disease process : Recommendations for the patient. Brief overview of the selected disease. How does nutrition relate to the disease process? Include basic nutrition facts.
How each complements in order to gain a comprehensive : Explain how each complements the other in order to gain a comprehensive understanding of the young client's concerns and situation.
Describe two social issues related to the course-specifice : Describe two social issues related to the course-specific case study for Claudia that inform a culturally competent social worker.
Design a public service ad to alter prevailing negative view : Design a public service ad to alter the prevailing negative views about disability. Describe your approach, the principles on which it is based, and end result

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implementation and application of data structures

Implementation and Application of Data Structures

  Prove that the cycle graph cn is not an interval graph

Prove that the cycle graph Cn is not an interval graph for any n ≥ 4? A bridge tournaments for five teams is to be scheduled so that each team plays two other teams ? The Petersen graph ?

  Evaluating an expression in postfix notation

Implement a program that can input an expression in postfix notation and output its value.

  Show the result of using the linear-time algorithm

Show the result of using the linear-time algorithm to builde a binary heap using the same input. Show the result of performing three deleteMin operations in the heap of the previous exercise.

  Do the depth-first search starting at vertex 2

Construct a trace table for the algorithm, using the digraph in Exercise 1 of Section 16.1. Whenever a new vertex to visit must be selected.

  Creating an automated checkout program

A local department store employee you to create an automated checkout program to expedite customers in a hurry. The checkout line can only allow 5-products for any one purchase.

  What is the linear data structure

what is the linear data structure ? Give example .Describe how an array is represented.

  Modify the constructor for the fraction class

Modify Constructor for the Fraction class so that GCD is used to reduce fractions immediately. This means that the __add__ function no longer needs to reduce.

  Searching of an item in a list of n numbers using linear

Ques:-Write a program in java for searching of an item in a list of n numbers using linear search.

  Complete the program that solves the eight queens

Complete the program that solves the Eight Queens problem. The program's output should look similar to:

  How a partition hash join would perform a natural join

How does the DBMS do this? What information does it use? How does it optimize access - implement optimizations for file data access

  How much time can elapse in the given algorithm

How much time can elapse in Algorithm 16.3 between a crash and its detection? Prove the eventual perfection of Algorithm 16.4. Is the re­ lation mep J.t eventually satisfied in every execution?

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