Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THE ANSWER HAS TO BE IN PSEUDOCODE. NO CODING OR OTHER EXPLANATION IS NECESSARY. ONLY PSEUDOCODE. Checking the Pseudoku conditions The next step in constructing

THE ANSWER HAS TO BE IN PSEUDOCODE. NO CODING OR OTHER EXPLANATION IS NECESSARY. ONLY 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 system 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 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.

To check whether a column contains all numbers from 1 to 4 in a puzzle vector, we will do the following:1. Create a stack called numbers, which contains all numbers from 1 to 4 2. Initialise a variable k to be 1 3. For the element k in a column, store the number in that element to a variable called value and call Search- Stack(numbers, value) 4. If the function returns FALSE, then we should return FALSE as a number appears twice or not at all in the stack 5. If the function returns the stack, increase the value of k by one and go to step 3 6. If after checking all elements in the column, SearchStack has not returned FALSE, we return TRUE In the next task you will need to complete a function that carries out this algorithm for column j of the input puzzle.

Here is the MAKEVECTOR function:

function MAKEVECTOR(row)

new Vector puzzle(4)

puzzle[1]

puzzle[2]

puzzle[3]

puzzle[4]

return puzzle end function

Element ! Element 2 Element 3 Element 1 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 SEARCHISTACK(stack, iter) 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 Let's demonstrate this with diagram. We have the following stack: Top 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: O Top The next task will be to complete a function that does this process of searching a stack and possibly removing an element

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago

Question

8. Demonstrate aspects of assessing group performance

Answered: 1 week ago