Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The Maze Problem-Computer Fundamentals-Assignment, Exercises of Computer Fundamentals

The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Maze, Problem, Boundary, Obstacles, Moveable, Region, Directions, Time, Coordinates, Cell

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Attempt any one of the following questions Due Date 10th Jan 2010
The Maze Problem
Objective
A rat is trapped in a maze at a preset starting position and needs to get to his cheese.
The cheese is present at a predefined finish point. Write a program to help the rat get
to his cheese by finding a path from a start position to a finish position.
Guidelines
Have a boundary around your maze and fill it up with all *s. The inner walls
(obstacles) are represented by all Xs and the moveable region is represented by all 0s.
The rat cannot go outside the boundary wall.
The rat can move in four directions at any point in time (R: right, L: left, U: up, D:
down). The rat cannot move diagonally. HaveaMxN matrix as the maze,
Checking right means adding {0,1} to the current coordinates.
Checking left means adding {0,-1} to the current coordinates.
Checking up means adding {-1,0} to the current coordinates.
Checking down means adding {1,0} to the current coordinates.
The rat will start off at the last row and the last column i.e. starting point = [M-1, N-
1].
From there, it tries to move to a cell which is free. A cell is free if it has 0 in it.
It tries all the 4 options one-by-one till it finds an empty cell. If it finds one, it moves
to that cell and marks it with a 1 (i.e. it has visited it once). Then it moves ahead from
that cell to an appropriate direction (R, L, U, and D).
If at a particular cell, it runs out of all the 4 options (that is it cannot move either right,
left, up or down), then it needs to backtrack. It backtracks till a point where it can
move ahead and be closer to the finish.Finish is defined as the [M-1, 0] cell.
If it reaches the exit point, it gets the cheese.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
0
0
0
X
0
0
0
X
0
X
0
0
0
*
*
X
X
0
X
X
X
0
X
0
X
X
X
X
*
*
X
X
0
X
X
X
0
X
0
X
X
X
X
*
*
0
0
0
0
0
X
0
0
0
X
0
0
0
*
*
0
X
X
X
0
X
0
X
0
X
X
X
0
*
*
0
X
X
X
0
X
0
X
0
X
X
X
0
*
*
0
X
0
0
0
0
0
X
0
0
X
X
0
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Start
Exit
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download The Maze Problem-Computer Fundamentals-Assignment and more Exercises Computer Fundamentals in PDF only on Docsity!

Attempt any one of the following questions – Due Date 10

th

Jan 2010

The Maze Problem

Objective A rat is trapped in a maze at a preset starting position and needs to get to his cheese. The cheese is present at a predefined finish point. Write a program to help the rat get to his cheese by finding a path from a start position to a finish position.

Guidelines

Have a boundary around your maze and fill it up with all *s. The inner walls (obstacles) are represented by all Xs and the moveable region is represented by all 0s. The rat cannot go outside the boundary wall.

The rat can move in four directions at any point in time (R: right, L: left, U: up, D: down). The rat cannot move diagonally. HaveaMxN matrix as the maze,

Checking right means adding {0,1} to the current coordinates.

Checking left means adding {0,-1} to the current coordinates.

Checking up means adding {-1,0} to the current coordinates.

Checking down means adding {1,0} to the current coordinates.

The rat will start off at the last row and the last column i.e. starting point = [M-1, N- 1].

From there, it tries to move to a cell which is free. A cell is free if it has 0 in it.

It tries all the 4 options one-by-one till it finds an empty cell. If it finds one, it moves to that cell and marks it with a 1 (i.e. it has visited it once). Then it moves ahead from that cell to an appropriate direction (R, L, U, and D).

If at a particular cell, it runs out of all the 4 options (that is it cannot move either right, left, up or down), then it needs to backtrack. It backtracks till a point where it can move ahead and be closer to the finish.Finish is defined as the [M-1, 0] cell.

If it reaches the exit point, it gets the cheese.


  • 0 0 0 X 0 0 0 X 0 X 0 0 0 0 *
  • X X 0 X X X 0 X 0 X 0 X X X *
  • X X 0 X X X 0 X 0 X 0 X X X *
  • 0 0 0 0 0 X 0 0 0 X 0 0 0 0 *
  • 0 X X X 0 X 0 X 0 X 0 X X 0 *
  • 0 X X X 0 X 0 X 0 X 0 X X 0 *
  • 0 X 0 0 0 0 0 X 0 0 0 X X 0 *

Exit Start

Solving system of linear equation

Objective Write a C program that solves system of linear equation using Gauss Elimination method. Guidelines System of linear equation:

This can be written in matrix form as Ax=b , where A is the coefficient matrix of variables, x is the vector of variables (x,y,z) and b is the vector of values on RHS of the above system of equation. 4 8 4 2 1 − 4 3 − 1 2

Since x is the vector of unknown so we need to solve Ax=b to find x. There are different techniques available to find x. For example Cramer's rule and x=A-1b Gauss Elimination Method: (Lal, 2007) Gauss elimination method was developed by 19th Century scientist Carl Fridrich Gauss (1809).(gauss_wiki, 2010)In this method finding A-1^ is not required. Matrix A is converted into an upper triangle matrix with all zeros in the lower matrix. Gauss Elimination is divided into two parts. First part is converting matrix A into upper triangle and second part is using back substitution to find values of variables

Example1: Use Gaussian elimination to solve the system of equations: Solution: Perform this sequence of Elementary Row Operations (E.R.O.'s) on the augmented matrix. Set the pivot column to column 1. Get a 1 in the diagonal position (underlined):

Next, get 0's below the pivot (underlined):

Now, let pivot column = second column. First, get a 1 in the diagonal position:

Solution to system of linear equation: Depending on the matrix you can get three kinds of solutions. Solution 1: see example 1, in this example you get unique solution to every variable. In this case you have to tell user that solution to this system is unique and show the solution to the user.

Solution 2: let’s look at another example.

2 𝑥 + 3𝑦 = 5 4 𝑥 + 6𝑦 = 10 When we apply Gaussian elimination on this system we get 2 3 4 6

𝑦 =^

Now if you want to apply back substitution on this you will not get a unique solution. You need to identify this case and have to tell user that this system does not have a unique solution.

Solution 3: Third case is the one when you don’t get any solution. For example 𝑥 + 𝑦 = 6 4 𝑥 + 4𝑦 = 10 When we apply Gaussian elimination on this system we get 1 1 4 4

𝑦 =^

In this case you cannot get any solution.

Bibliography

gauss_wiki. (2010, 12 21). Gaussian_Elimination. Retrieved 12 21, 2010, from wikipedia: http://en.wikipedia.org/wiki/Gaussian_elimination

Lal, A. K. ( 2007, 09 12).. Retrieved december 21, 2010, from http://nptel.iitm.ac.in/courses/Webcourse-contents/IIT- KANPUR/mathematics-2/node18.html

mat10. (n.d.). Retrieved December 21, 2010, from mathonweb: http://mathonweb.com/help/backgd3e.htm