Write program to find solution of a minimal number of steps

Assignment Help C/C++ Programming
Reference no: EM131307336

COSCI 21a, Programming Assignment

Purpose: Experience with some basic data structures, including circular queues, linked lists, hash tables, and specifically with pointers and the associated dynamic memory allocation.

Problem: Write a C program to find a solution of a minimal number of steps to the Nite and Day puzzle, where one step is defined as moving a piece vertically or horizontally to an adjacent unoccupied square, and the two $ pieces cannot move:

2060_Figure.png

Guidelines: At a high level, your program should perform breadth-first as described by this pseudo-code:

INSERT start position into an initially empty hash table

ENQUEUE start position

while (goal position not found) do begin

DEQUEUE a position P

for each position  X  that is reachable from  P  by one move, but is not in the hash table,

INSERT X into the hash table and ENQUEUE X.

end

Output a solution by reversing the sequence going from the goal back to the start position.

Although there are a number alternatives, for this assignment you must use these two data structures:

Hash Table:  Stores all positions seen thus far.

  • Each entry is either a NULL pointer or a pointer to the first vertex of a singly linked list of the positions that have thus far hashed to that bucket.
  • Each position stored in the hash table is a structure that includes the hash table bucket linked list pointer, a pointer to the position from which this position came (NULL for the start position), the piece that has moved (0 for the start position), the direction in which the piece moved (0 for the start position), and an array representing the position.

Queue: Stores the positions waiting to be explored.

  • Each entry is a pointer to a position in the hash table.
  • A circular queue array implementation is used as presented in class.

There are a number of ways to output the solution once the goal position has been reached (see the questions); for full credit, you must reverse the back pointers as the path back to the start is traversed, and then traverse them in the forward direction to print the solution.

Requirements for writing your program:

In order to facilitate grading, you are provided these two files; they may not be modified (the grader will be using exactly these files, without modifications, when compiling your code):

Puzzle.h

The definition of the puzzle, including the size you must use for your queue and hash table.

Output.h

The format of your output must be the positions visited in each step of the solution followed by statistics printed by using the functions in Output.h (see the sample output for the AB Puzzle).

A software tool will be employed to check your output. All output must be produced by calling the functions in Output.h; that is, the code you submit should have no output statements (e.g., no printf statements). Also, your code my not read or write to any files.

Note: A board is defined in these functions as a simple one dimensional array. However, you can use any representation for a puzzle position you like. For example, if you are representing boards with 2-dimensional arrays, you can copy the board information to a temporary one dimensional array and pass that to the function in Output.h that prints a position.

Questions:

Note: Although the questions will be graded on a nominal scale of 10 points per question, there is no specific percentage of the total assignment score for they count. For programs that do not work, good answers to questions may increase partial credit, and for programs that work, poor or missing answers to questions may cause loss of credit.  Following your answers to these questions you may include any additional comments, explanations, etc. that you would like the grader to read.

1. Compare time and space used if instead of a separate circular queue, the queue was incorporated into the position structures a singly linked list (i.e., position structures now include a NEXT field).

2. Compare the worst-case time and average time of representing a hash table bucket as a singly linked list versus representing a bucket with a binary search tree; consider both the situation where the hash table size is larger than the number of positions, and when it is set to 3.

3. Depending on the puzzle and size of the hash table, the number of positions may exceed the number of buckets. Describe how you would implement closed hashing to address this issue, and compare the time and space with the open hashing.

4. The assignment asked you to print a solution by reversing back pointers. Another approach is to push onto a stack pointers to the positions visited as back pointers are traversed. A third alternative is the following recursive function to print the path. In terms of time and space, ease of programming, and issues such as not knowing the length of the solution in advance, compare these three options.

5. When a position X is dequeued, the program could not generate the position Y that results moving back in the same direction from which X came, or it could generate all positions reachable from X and discover that Y was already in the hash table. Discuss the pros and cons of these alternatives.

6. How you would generalize your program to solve puzzles like the Traffic Jam Puzzle:

7. In this assignment, one move is moving one piece one unit in one direction, and solutions expressed using this type of unit movement tend to be a bit tedious. Two other types of movement are straight movement (one piece  can be moved any distance in a single direction) and  rectilinear movement (one piece can be moved  any distance along a  rectilinear path). Note that one cannot in general combine successive moves of a minimal solution for the unit metric to obtain a minimal solution in one of the other two metrics. Discuss how you could generalize your program to find minimal solutions for the straight and rectilinear metrics.

8. What was the most difficult part of this assignment? Would it have helped if you were allowed to write your program using multiple files? If instead of being required to write this code on your own, if you  could divide  the work of writing and debugging with three other  students, how would you organize the project in such a way so as to most efficiently complete the project while having a relatively even work load between the four of you?

Attachment:- Assignment.zip

Reference no: EM131307336

Questions Cloud

What is the effective rate of interest : Kevin was told that his loan bears 12% interest. Knowing that the compounding term will be monthly, what is the effective rate of interest?
Can a server retrieve a file from the client site : FTP can transfer files between two hosts using different operating systems with different file formats. What is the reason?
What sum of money due at the end of 6 years : What sum of money due at the end of 6 years is equivalent to $2,100 due at the end of 10 years if the compound interest rate is 10½ %?
Review the history of the product : Review the history of the product and then prepare a brief report outlining how the makers of Arm and Hammer baking soda have been able to extend the product's lifecycle.
Write program to find solution of a minimal number of steps : COSCI 21a, Programming Assignment. Problem: Write a C program to find a solution of a minimal number of steps to the Nite and Day puzzle, where one step is defined as moving a piece vertically or horizontally to an adjacent unoccupied square, and ..
In what way can this application be useful : The TELNET application has no commands such as those found in FTP or HTTP to allow the user to do something such as transfer a file or access a web page. In what way can this application be useful?
Prepare a paper on radiation therapy or hyperbaric medicine : Please prepare a complete, concise research paper on radiation therapy or hyperbaric medicine (four pages, typed, double spaced, with references).
How is cancer diagnosed and treated in companion animals : How is cancer diagnosed and treated in companion animals? Consider radiography, ultrasound, nuclear imaging and radiation therapy in your paper.
List the characteristics of successful aging : List the characteristics of successful aging.Explain how the growing population of older adults will affect society, including considerations of economics,health care, living arrangements, and ethical and moral issues.Explain the biological and p..

Reviews

len1307336

12/10/2016 4:39:44 AM

The first file (p1.pdf is the main file needed. The other files are needed as supplements or have hints/can help with the assignment but p1.pdf is the main file needed.) Info on the assignment: PUZZLE H: Definition of the puzzle. Includes constants that define the size you should use for the queue array, the size you should use for the hash table array, and the number of bucket sizes for which you keep statistics. OUTPUT..H: (THIS IS UPLOADED AS THE OUTPUT.txt but should be output.h) All output must be produced by calling the functions in this file, where he format of your output is the positions visited followed by statistics (see the sample output). Note that a board is defined in these functions as a simple one dimensional array. However, you can use any representation for a puzzle position you like. For example, if you are representing boards with 2-dimensional arrays, you can copy the board information to a one dimensional temporary array and pass that to the function that prints a position.

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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