Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER SHOULD BE IN CLEAR AND CONCISE PSEUDOCODE Checking the Pseudoku conditions The next step in constructing the algorithm is to write methods to decide

ANSWER SHOULD BE IN CLEAR AND CONCISE PSEUDOCODE

Checking the Pseudoku conditions

The next step in constructing the algorithm is to write methods to decide if the Pseudoku conditions are satisfied. If we start with the output of the function MakeVector(row), then all of the row conditions are satisfied as long as row is a four-element vector with the numbers 1 to 4 only appearing once. However, the column conditions are not satisfied: only one number appears in each column (four times). The 2-by-2 sub-grid conditions are also not satisfied: in each sub-grid only two numbers appear (twice).

We need a convenient way to refer to elements of the two-dimensional puzzle. We will use a coordinate sys- tem of (row,col) for the four-element vector puzzle as produced by MakeVector: row is the number of the element of puzzle that we care about, and col is the number of the element in puzzle[row] that we care about. Consider the following vector:

image text in transcribed

The coordinates of the element in yellow are (3,2), for example. So to select the value stored there we use the syntax puzzle[3][2], since we are looking at the second element in puzzle[3]. Using this coordinate system to re- fer to the 2-by-2 sub-grids, for example, the top-left sub-grid will consist of the elements (1,1), (1,2), (2,1) and (2,2).

You will check the Pseudoku conditions using a stack. In particular, you will start with a stack containing all numbers from 1 to 4, and then inspect each element in each column (or sub-grid) to see if the number in that element is stored in the stack: if it is stored in the stack, pop that value from the stack and return the stack; otherwise, return false. This process will be repeated for every element in a column or sub-grid. If, at the end of checking every element, the stack is empty then all numbers appear in the the column or sub-grid; if the stack is not empty, then not all numbers from 1 to 4 appear.

We will complete a function called SearchStack(stack, item) that will search a stack for the value item: if item is in one of the elements of the stack, we remove that element storing item. Otherwise, the function should return FALSE Lets demonstrate this with diagram. We have the following stack:

image text in transcribed

We want to look for the value 3 in the stack and remove it if it is there, otherwise if it is not there, return FALSE. The value 3 is stored in the stack so we then need to remove it so the stack could look like this:

image text in transcribed

The task will be to complete a function that does this process of searching a stack and possibly removing an element.

Task 4: Complete the following function:

function SearchStack(stack, item)

...

end function

This function will take a stack and a value (called item) as input parameters, and return FALSE if item is not stored in the stack, otherwise return the stack without the element storing item.

Element 1 2 4 1 3 Element 2 2 4 1 3 Element 3 2 4 3 Element 4 2 4 1 3 1 2 3 4 . Top 1 2 4 1 Top

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions