Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92061967

Have any Question?


Related Questions in C/C++

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

  • 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