Worksheets#17 Arrays, Records, Tuples and Hash Tables
Total questions: 15
Worksheet time: 8mins
Name
Class
Date
1.
2. Which of these applies to an array?
a)
A. Elements must be of the same data type
b)
B. Elements can be of any data type as there are no type rules on the array
c)
C. One element can contain a single value while other elements contain multiple values or data structures
d)
D. Specific array index values can be set to different numbers where necessary
2.
3. In the array nums = {0,1,5,2,1), which of the following is false?
a)
A. There are five elements
b)
B. 5 is one element
c)
C. There are two elements
d)
D. Two elements have the same value
3.
4. In the following array, which of these commands would determine the number of characters in "Crab"?
zoo = ["Pig", "Wolf", "Crab"],
a)
A. zoo.length[3]
b)
B. zoo[2].length
c)
C. zoo[3].length
d)
D. zoo[3][4]
4.
5. Which of the following would place an 'X' as the first element in a 2D array of characters which has the identifier 'grid'?
a)
A. grid.length(0)[0] = 'X'
b)
B. grid]='X'
c)
C. grid[0][0] = 'X'
d)
D. grid['X'].charAt(0)
5.
6. Twenty-seven different coloured cubes are arranged into a larger cube shape. The colour of each individual cube is unique and is represented as a 5-bit colour code, e.g. 00000=black, 10101=pink. A 3D array of strings is used to represent the arrangement of the 27 smaller cubes into a 3x3x3 arrangement.
If cube [0][0][0] represents the top-left cube on the top row, which of these represents the bottom-right cube on the bottom row?
a)
A. cube[0][1][2]
b)
B. cube[3][3][3]
c)
C. cube[0][3][0]
d)
D. cube[2][2][2]
6.
7. Which of these is the most suitable data structure for modelling a chess board in a computerised chess game in such a way that the squares on the board store the value of the chess piece at that square?
a)
A. Tuple
b)
B. 3D array
c)
C. 2D array
d)
D. 1D array
7.
8. When visiting all of the elements of a 2D array, which of these approaches is suitable?
a)
A. Use two nested iterative structures. Each time you progress to a new row, recalculate the length of that row as it may not contain the same number of columns as the row before it.
b)
B. Use two nested iterative structures. Each time you progress to a new row, you will not have to recalculate the length of that row as it will be the same as the row before it.
c)
C. Use a do-while (aka repeat-until) loop. It has built-in capabilities to handle 2D arrays efficiently.
d)
D. Use three nested iterative structures. The two inner iterative structures (FOR loops are commonly used) will visit each of the elements, but a third outer loop is required to manage any additional checks such as IF statements that need to be carried out.
8.
9. A program is iterating through a 2D array, keeping track of 'rows' and
'columns' using variables called r and c. The program is seeking to add up all of the positive numbers found in the array known as 'arr' and store this in a variable called 'total', which is initialised to 0 prior to the iteration starting.
Which of these is the correct syntax to be used?
a)
A. if(arr[r][c] < 0) { arr[c][r] = total + arr[r][c]; }
b)
B. if(arr[c] [r] < 0) { total = total + arr[r][c]; }
c)
C. if(arr[r][c] > 0) { total = total + arr[r][c]; }
d)
D. if(arr[c][r] > 0) { arr[c][r]= total + arr[c][r]; }
9.
10. Which of these is true about records compared to arrays?
a)
A. Records are not accessed via index values whereas arrays are
b)
B. Arrays and records are accessed using index values but numeric indexing is more flexible in records
c)
C. Records are accessed using either field designators (identifiers for each field) or numeric indexes (like an array would be), depending on which is more convenient
d)
D. Zero-based indexing is common when arrays are used but compulsory when records are used
10.
11. In what way is a tuple similar to an array?
a)
A. Its values can be changed
b)
B. Once it has been created it cannot grow or shrink in length
c)
C. It is a primitive data type
d)
D. Its values can all be different data types
11.
12. Records and tuples have rules in common. Which one of these is an example of a rule that they both share?
a)
A. They both use numeric indexing
b)
B. They can store a mixture of data types
c)
C. They can grow and shrink in size
d)
D. Iteration can be used to step through their contents
12.
13. If this is a tuple: ('5',5,"five"), is it valid?
a)
A. Yes
b)
B. No, it contains too many values
c)
C. No, it contains too many data types
d)
D. No, it is unusable
13.
14. Here are some tuples. Which one would yield the result 'Dragon' if the following line of code was used
tup [1]
a)
A. tup = (0,4,"Don","Rage", "Ron","Dragon")
b)
B. tup = ("Dragon", "Dang", "Rang", "Oran")
c)
C. tup = ("Ron","Dragon",orange,1)
d)
D. tup = (1,0,"Dragon")
14.
15. Which of these is false?
a)
A. Arrays are dynamic, mutable data structures
b)
B. Records are mutable data structures
c)
C. Tuples are immutable data structures
d)
D. Neither arrays nor tuples are dynamic data structures
15.
16. What is meant by a static data structure?
a)
A. The values can be changed
b)
B. The values cannot be changed
c)
C. The size can be changed
d)
D. The size cannot be changed
100 %
