Arrays questions and answers
Questions
Q1. Define an array.
Q2. Why do all arrays need a name?
Q3. How many different datatypes can an array hold?
Q4. What is meant by a one dimensional array?
Q5. What is meant by a two dimensional array?
Q6. What is an ‘element’ when referring to arrays?
Q7. Using an example, show how you would read and write to an element in a one dimensional array.
Q8. Using an example, show how you would read and write to an element in a two dimensional array.
Q9. Describe one good point and one bad point about an array.
Q10. State a language that doesn’t use arrays and state what data structures it typically uses instead.
Answers
Q1. An array is "a set of data items of the same type grouped together using a single identifier".
Q2. Arrays need their own unique name because a program might have more than one array in it and you need to know which one you are referring to.
Q3. Arrays can only hold one datatype.
Q4. A one dimensional array can be thought of as a single column of data items.
Q5. A two dimensional array can be thought of as a table of data, with the data items arranged in rows and columns.
Q6. An element is a single item of data in an array.
Q7. To read a value into the variable ‘temp’ from a one dimensional array, you could use temp = arrayTotal [4]. To write to element 4, you might do this: arrayTotal [4] = temp.
Q8. To read a value into a variable temp from a two dimensional array, you could use temp = arrayTotal [4, 7]. To write to element [4, 7], you might do this: arrayTotal [4, 7] = temp.
Q9. Arrays are easy to set up, the space is reserved so always available, you can access an element directly and you can efficiently process large blocks of data. Arrays can waste RAM if they are not used, you have to estimate the array size in advance as the size is defined and reserved at runtime, they can only hold one data type and an array may need to be processed if the data they hold has to be organised in some way, which can add to programming complexity.
Q10. Programmers using Python can make use of an array library but they are much more likely to use a list data structure, as it is more flexible than an array.