Question: I am completely stuck on task 3 This is what I have for task 2 Cyclic permutation of row vectors Consider the following vector: Element

I am completely stuck on task 3

I am completely stuck on task 3 This is what I have

for task 2 Cyclic permutation of row vectors Consider the following vector:

This is what I have for task 2

Element 1 3 Element 2 2 4 Element 3 2 4 Element

Cyclic permutation of row vectors Consider the following vector: Element 1 3 Element 2 2 4 Element 3 2 4 Element 4 2 4 3 This does not satisfy the Pseudoku conditions since in each column only one number appears. The algorithm for generating Pseudoku puzzles will cyclically permute the elements in the rows until the Pseudoku conditions are satisfied. A cyclic permutation of each row will shift all values of the elements one place to the left (or the right) with the value at the end going to the other end. For example, for the second element in the vector above, if we cyclically permute all elements one place to the left we will have: 2 4 1 3 Cyclic permutation 4 1 3 2 Given a four-element vector and an integer p between 0 and 3 (inclusive) we want to write a function to cyclically permute the values in the vector by p elements to the left. An elegant way to do this is to use the queue abstract data structure. All values in a vector will be enqueued to an empty queue from left to right, e.g. the first row vector in the vector above will give the following queue: 3 1 4 2 Tail Head To cyclically permute all values one place to the left we enqueue the value stored at the head, and then dequeue the queue. This process will then give the following queue: 2 Tail Head To cyclically permute the values we can just repeat multiple times this process of enqueueing the value at the head and then dequeueing. When we are finished with this process we then just copy the values stored in the queue to our original vector and return this vector. The next task is to formalise this process into a function in pseudocode. Task 2: Complete the following function template: function PERMUTEVECTOR(row, p) if p = 0 then return row end if new Queue a end function This function should return that input vector row with its values cyclically permuted by p elements to the left: should be a number between 0 and 3 (inclusive). To be able to get full marks you need to use the queue abstract data structure appropriately as outlined above. [6 marks] The function PERMUTEVECTOR, once completed, will only cyclically permute one vector. The next task is to take a vector puzzle and apply PERMUTEVECTOR to its bottom three elements. In particular, given vector puzzle then elements 2, 3 and 4 of puzzle will be cyclically permuted x, y and z places to the left respectively. Task 3: Complete the following function template: function PERMUTERows(puzzle, x, y, z) end function The function should return the input vector puzzle but with elements puzzle[2], puzzle[3] and puzzle[4] cyclically permuted by x, y and z elements respectively to the left: x, y and z should all be numbers between 0 and 3 (inclusive). To be able to get full marks you should call the function PERMUTEVECTOR appropriately. You do not need to loop over integers x, y and z. [4 marks] TASK 2 function PermutateVector(row,p) if p = 0 then return row end if new Queue a for (1 sis 4) do ENQUEUE[row[i],q] return a end for for (1 sj

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!