Section 9.13 Chapter Summary
Subsection 9.13.1 Technical Terms
|array initializer||array length|
|binary search||data structure|
|insertion sort||multidimensional array|
|one-dimensional array||polymorphic sort method|
|selection sort||sequential search|
Subsection 9.13.2 Important Points
- An array is a named collection of contiguous storage locations, each of which stores a data item of the same data type. Each element of an array is referred to by a subscript —that is, by its position in the array. If the array contains N elements, then its length is N and its indexes are
0, 1, N-1.
- Array elements are referred to using the following subscript notation arrayname[subscript], where arrayname is any valid identifier, and subscript is an integer value in the range 0 to
arrayname.length - 1. The array’s
lengthinstance variable can be used as a bound for loops that process the array.
- An array declaration provides the name and type of the array. An array instantiation uses the keyword
newand causes the compiler to allocate memory for the array’s elements:
int arr; // Declare a one-dimensional array variable arr = new int;// Allocate 15 int locations for it
- Multidimensional arrays have arrays as their components:
int twoDarr; // Declare a two-dimensional array variable twoDarr = new int; // Allocate 150 int locations
- An array’s values must be initialized by assigning values to each array location. An initializer expression may be included as part of the array declaration.
- Insertion sort and selection sort are examples of array sorting algorithms. Both algorithms require several passes over the array.
- When an array is passed as a argument to a method, a reference to the array is passed rather than the entire array itself.
- Swapping two elements of an array, or any two locations in memory, requires the use of a temporary variable.
- Sequential search and binary search are examples of array searching algorithms. Binary search requires that the array be sorted.
- For multidimensional arrays, each dimension of the array has its own
- Inheritance and polymorphism are useful design features for developing a hierarchy of computer games.
Solutions 9.13.3 Solutions to Self-Study Exercises
9.2 One-Dimensional Arrays
9.2.3 Array Allocation
22.214.171.124. How many bytes double array?
126.96.36.199. How many bytes char array?
188.8.131.52. How many bytes String array?
184.108.40.206. How many bytes Student array?
9.2.5 Assigning and Using Array Values
220.127.116.11. What’s the value?
18.104.22.168. What’s the value?
22.214.171.124. Access the last element.
126.96.36.199. Assign to the first element.
9.3 Simple Array Examples
9.3.1. Square Roots.
9.4 Example: Counting Letter Frequencies
9.4.2 A Class to Count Letter Frequencies
188.8.131.52. Letter Frequencies.
9.5 Array Algorithms: Sorting
9.5.1 Insertion Sort
Self Study Exercise
184.108.40.206. Run Insertion Sort.
220.127.116.11. Insertion sort trace 1.
18.104.22.168. Insertion sort trace 2.
9.5.2 Selection Sort
22.214.171.124. Selection sort trace 1.
126.96.36.199. Selection sort trace 2.
9.5.3 Algorithm: Swapping Memory Elements
188.8.131.52. Swapping values in variables.
9.5.4 Passing a Value and Passing a Reference
184.108.40.206. Array Parameter.
220.127.116.11. What’s the value?
18.104.22.168. Selection sort.
9.6 Array Algorithms: Searching
9.6.2 Binary Search
22.214.171.124. Binary search.
9.7 Two-Dimensional Arrays
9.7.1 Example: Rainfall Array
126.96.36.199. Two-D array.
9.7.3 Passing Part of an Array to a Method
188.8.131.52. Newspaper sales.
9.9 OBJECT-ORIENTED DESIGN: Polymorphic Sorting (Optional)
184.108.40.206. Polymorphic Sort.
You have attempted of activities on this page.