What are the design issues for arrays?
Issues include
- legal subscript types
- range checking of subscripts
- when are subscript ranges bound?
- when does array allocation take place?
- are ragged or rectangular multidimensioned arrays allowed, or both?
- allowed slice types.
.
Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic arrays. What are the advantages of each?
Static: Subscript ranges and storage are bound before run time. Advantage: Efficiency (no dynamic allocation).
Fixed stack-dynamic: Storage is allocated at declaration time, but size is static. Advantage: Space efficiency.
Stack-dynamic: Range and storage are bound dynamically at run time. Advantage: Flexibility.
Fixed heap-dynamic: Subscript ranges and storage binding are fixed after allocation from the heap. Advantage: Flexibility (size fits the problem).
Heap-dynamic: Subscript ranges and storage allocation can change during execution. Advantage: Maximum flexibility.
What happens when a nonexistent element of an array is referenced in Perl?
It yields undef, but no error is reported.
What languages support negative subscripts?
Ruby, Lua, and Perl.
What languages support array slices with stepsizes?
Python.
What array initialization feature is available in Ada that is not available in other common imperative languages?
Ada allows initializing specific indices directly using the arrow operator => and an others clause for remaining elements.
What is an aggregate constant?
A parenthesized list of values used to initialize an array.
What array operations are provided specifically for single-dimensioned arrays in Ada?
Catenation (specified by &).
Define row major order and column major order.
Row major: Elements are stored by rows (first subscript varies slowest).
Column major: Elements are stored by columns (last subscript varies slowest).
What is an access function for an array?
It is a mapping from the array name and set of subscript values to the address of an element.
What are the required entries in a Java array descriptor, and when must they be stored?
It requires the fixed maximum length and current length, stored at run time (because Java arrays are fixed heap-dynamic).
What is the structure of an associative array?
It is an unordered collection of data elements indexed by an equal number of keys (each element is a key-value pair).
How does JavaScript support sparse arrays?
JavaScript supports sparse arrays by treating them as objects containing specific items, not as a reserved block of empty space.