Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

what would be the procedure for an multi-dimensional array first read integer N

ID: 3866345 • Letter: W

Question

what would be the procedure for an multi-dimensional array first read integer N which denotes the number of dimensions of a multi-dimensional array. Next read the dimensions d0 d1 … dN–1, so the array will have dimensions d0 by d1 by … by dN–1. Next read the initial values of the array using array aggregate notation. The array elements will always include the value 0 and will always consist of distinct consecutive non-negative integers, but these integers might be arranged in any order.

examples input:

That each move relocates the 0 element to a new position, and is specified as a dimension and a distance. The dimension k will be in the range 0 to N–1, and the distance indicates how far the 0 element will travel (positive indicates increasing indexes, and negative indicates decreasing indexes). However, to prevent reaching outside the range of valid indexes 0 to dk–1, the indexes along each dimension will wrap around in a circular fashion. As the value 0 travels the specified distance, it swaps places with each other value it encounters. The goal is to find a sequence of moves that leads to the array configuration such that all the array elements will be in ascending order when written in aggregate notation (or in row-major order). Were the correct sequence of moves is not necessarily unique. Several examples follow; each example shows an input and then two of the many possible corresponding output sequences. Your final output should only show the move sequence, not the array contents.

examples:

How could this be solvied using a priority queue rather than either a FIFO queue or a stack. To compute a priority for a given array configuration, by measuring how far each array element currently is from its desired final location, and then take the sum of all these distances. If the program explores configurations in the order of smallest priority first in an similar approach to Dijkstra’s algorithm.

3 4 14,1,2,7111,8,3,9, (5,10,0,6 11 8 3 9 5 10 0 6

Explanation / Answer

Answer: See the presudo code below:

1. Read a multidimensional array:

--------------------------------------------------------------------

1. Read number of dimensions, N, for array.

2. //loop to read sizes of N dimensions

3. For each i=0:N-1

4. Read value d[i] of size of each dimension

5. End For loop

6. Allocate an array A[d[0]][d[1]]--------------------[d[N-1]] to store elements

7. Assign elements in aggregate notation to A.

Note: For such kind of procedure, it would be better to specify maximum number of dimension procedure can support.

Rest of the description looks incompelete. Hence specify complete description for full solution. Also the name of language in which required.