Chapter 8, Arrays

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Describe how to pass an array as an argument to a module or a function?

Passing an array as an argument typically requires that you pass two arguments: 1. the array itself, and 2. an integer that specifies the number of elements in the array.

What does "array bounds checking" mean?

Programs do not allow the use of an invalid array subscript.

What is usually the first subscript in an array?

Subscripts are used to identify specific elements in an array. The first element is assigned the subscript 0, the second element is assigned the subscript 1, etc.

How do you declare a two-dimensional array?

Two size declarators are required, the first one for the number of rows and the second for the number of columns.

Which array element does the sequential search algorithm first look at?

Uses a loop to sequentially step through the array, starting with the first element.

What is an initialization list?

The series of values separated with commas. These values are stored in the array elements in the order they appear. in the list.

What is an array element?

The storage locations in an array are known as elements.

Briefly describe how you calculate the total of the values in an array.

To calculate the total of the values in an array, you use a loop with an accumulator variable. The loop steps through the array, adding the value of each array in the element to the accumulator.

Describe the algorithm for finding the highest value in the array.

1. Create a value to hold the highest value. 2. Assign the value at element 0 to the highest value. 3. Use a loop to step through the rest of the array elements, beginning at element 1 Each time the loop iterates, it compares an array element to the highest variable. If the array element is greater than the highest variable, then the value in the array element is assigned to the highest variable. When the loop finishes, the highest variable will contain the highest value in the array.

Briefly describe how you get the average of the values in the array.

1. Obtain the total of the values. 2. Divide the total by the number of elements in the array.

What is a one-dimensional array?

A data structure that allows a list of items to be stored with the capability of accessing each item by pointing to its location within the array

What is a search algorithm?

A technique to locate a specific item in a larger collection of data, such as an array.

What is an array size declarator?

The number inside the brackets. A size declarator specifies the number of values that the array can hold.

Can you store a mixture of data types in an array?

An array can hold a group of values. All of the values in an array must be of the same data type. You can have an array of Integers, and array of Reals, or an array of Strings, but you cannot have a mixture of data types in an array.

How do you copy the contents of one array to another array?

Assign the individual elements of the array that you are copying to the elements of the other array. Usually this is best done with a loop.

How do you establish a relationship between the data store in two parallel arrays?

By using the same subscript, you can establish relationships between data stored in two or more arrays.

What is a two-dimensional array?

Can hold multiple sets of data, typically having rows and columns of elements.

How do you process the data in a two-dimensional array?

Each element has two subscripts, one for its row and another for its columns.

What is a subscript?

Each element in an array is assigned as a unique number known as a subscript (aka indexes)

How many elements does the sequential search algorithm look at in the case that the search value is not found in the array?

If the value being searched for is not in the array, the algorithm unsuccessfully searches to the end of the array.

In most languages, can the size of an array be changed while the program is running?

In most languages, an array's size cannot be changed while the program is running. If you have written a program that uses an array and then find that you must change the array's size, you have to change the array's size declarator in the sources code. Then you recompile the program with the new size declarator

What does the loop do in the sequential search algorithm? What happens when he value being searched for is found?

It compares the search element with the value being searched for and stops when the value is found or the end of the array is encountered.

How do you look for a partial string match when searching an array of strings for a value.

Most languages provide a library function that can determine whether a string partially matches another string. The "contains" function accepts two strings as arguments and it returns True if the first string contains the second string; otherwise, the function returns False.

What is an "off-by-one" error?

Occurs when a loop iterates one time too many or one time too few.


Set pelajaran terkait

Chp. 20 PrepU Questions: Assessment of Respiratory Function (Exam 1)

View Set

Module 77: Prejudice and Discrimination [AP Psych]

View Set

Real Estate Practice Exam: All Questions

View Set