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

Arrays can be typed by a mapping from an index set to the array element type. Co

ID: 3828818 • Letter: A

Question

Arrays can be typed by a mapping from an index set to the array element type. Consider the following example type definitions in Pascal. type Color =(red, green, blue); Pixel = array [Color] of 0..1; The type of Pixel is {red, green, blue} {0, 1}. (a) Suppose now you want to define a 2-dimensional array called DoublePixel, which uses Color as the index set in both dimensions and has only 0's and 1 's as values for each array element. Suggest two ways of typing DoublePixel. You do not have to give the Pascal codes for the type definition. Just give the two types in mathematical notations. (b) State which one of your proposed approaches to typing is better. Explain why.

Explanation / Answer

I would suggest two implementations of Row major and column major.

array [] [] = { {<COLOR, bit>}, { COLOR,<bit>}, { COLOR, <bit>}....} // bit an be 0 or 1

or

array [] [] = {

[COLOR}

{bit1, bit2, bit3 }

}

First way in my view is better becausde it works as a key value pair, a much efficient model.

Extract value from the given key.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote