Array Flashcards

1
Q

What is the term used to describe this?

  • Series or list of variables in computer
    memory
  • All variables share the same name and
    data type
  • Each variable has a different subscript

Understanding Array

A

Arrays

Understanding Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the term used to describe this?

What is the number that indicates the position of a
particular item within an array?

Understanding Array

A

Subscripts or
Index

Understanding Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the term used to describe this?

  • Each item has same name and same data type
  • Each separate item is one blank an item in the array
  • Array elements are contiguous in memory

How Arrays Occupy Computer Memory

A

Element

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is this variable initialized or uninitialized?

num someVals[3]

How Arrays Occupy Computer Memory

A

Uninitialized

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is this variable initialized or unintialized?

num someVals[3] = 25, 36, 47

How Arrays Occupy Computer Memory

A

Initialized

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the term used to describe this?

This is the number of
elements it will
hold.

How Arrays Occupy Computer Memory

A

Size of the array

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the term used to describe this?

This is the number of
elements it will
hold.

How Arrays Occupy Computer Memory

A

Size of the array

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the term used to describe this?

All elements have same group name
Individual elements have blank subscript
Subscript indicates blank from first element
Subscripts are a blank of integer

How Arrays Occupy Computer Memory

A

unique
distance
sequence

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False?

Subscripts placed in parentheses ( ) or brackets { }, [ ]
following group name
Syntax depends on programming language

How Arrays Occupy Computer Memory

A

True

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True or False?

Subscripts placed in parentheses ( ) or brackets { }, [ ]
following group name
Syntax depends on programming language

How Arrays Occupy Computer Memory

A

True

How Arrays Occupy Computer Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is this an example of?

Example: Human Resources Department Dependents report
List employees who have claimed zero through five
dependents
* Assume no employee has more than five dependents
* Application produces counts for dependent categories
* Uses series of decisions
* Application does not scale up to more dependents

Manipulating an Array to Replace Nested Decisions

A

Manipulating an Array to Replace Nested Decisions

Manipulating an Array to Replace Nested Decisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False

Array subscript variable must be:
Numeric with no decimal places
Initialized to 0
Incremented by 1 each time the logic
passes through the loop

Manipulating an Array to Replace Nested Decisions

A

True

Manipulating an Array to Replace Nested Decisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False

Constants are used to hold the
size of an array, its values, and as a subscript.

Using Constants with Arrays

A

True

Using Constants with Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is this an example of?

Avoid “magic numbers” (unnamed constants)
* Declare a named numeric constant to be used every time
array is accessed
* Make sure any subscript remains less than the constant
value
* Constant created automatically in many languages

Using Constants with Arrays

A

Constants

Using Constants with Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is this an example of?

Sometimes the values stored in arrays should be blank
Example:
~~~
string MONTH[12] = “January”, “February”, “March”, “April”, “May”,
“June”, “July”, “August”, “September”, “October“, “November”, “December”
~~~

Using Constants with Arrays

A

Constants

Using Constants with Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is this an example of?

Example
Declare a named constant as num INDIANA = 5
Display value with:
output salesArray[INDIANA]

Using Constants with Arrays

A

Use a numeric constant as a subscript to an array

Using Constants with Arrays

17
Q

What is this an example of?

Sometimes must search through an array to find a value
Example: ```
mail-order business
customer name, address,
item number, quantity ordered
Item numbers are three-digit, non-consecutive numbers
Customer orders an item, check if item number is valid
Create an array that holds valid item numbers
Search array for exact match
~~~

Searching an Array

A

Searching an Array

Searching an Array

18
Q

What is this an example of?

  • Set a subscript variable to 0 to start at the first element
  • Initialize a flag variable to false to indicate the desired value has not been found
  • Examine each element in the array
  • If the value matches, set the flag to True
  • If the value does not match, increment the
  • subscript and examine the next array element

Searching an Array

A

Technique for searching an array

Searching an Array

19
Q

What is this an example of?

What is the variable
that indicates
whether an
event occurred?

Searching an Array

A

Flag

Searching an Array

20
Q

What is this an example of?

mail-order business
Two arrays, each with six elements
Valid item numbers
Valid item prices
Each price in valid item price array in same position as 
corresponding item in valid item number array

Using Parallel Arrays

A

Using Parallel Arrays

Using Parallel Arrays

21
Q

What is this an example of?

  • Each element in one array associated with element in same relative position in other array
  • Look through valid item array for customer item
  • When match is found, get price from item price array

Using Parallel Arrays

A

Parallel Arrays

Using Parallel Arrays

22
Q

What is this an example of?

  • Two or more arrays contain related data
  • A subscript relates the arrays
  • Elements at the same position in each array are logically related

Using Parallel Arrays

A

Using Parallel Arrays

Using Parallel Arrays

23
Q

What is this an example of?

  • Program should stop searching the array when a match is found
  • Setting a variable to a specific value instead of letting normal processing set it
  • Improves efficiency
  • The larger the array, the better the improvement by doing an early exit

Improving Search Efficiency

A

Improving Search Efficiency

Improving Search Efficiency

24
Q

What is this an example of?

Sometimes programmers want to work with ranges of values in
arrays
Example: ```
mail-order business
Read customer order data; determine discount based on
quantity ordered
First approach
Array with as many elements as each possible order quantity
Store appropriate discount for each possible order quantity
~~~

Searching an Array for a Range Match

A

Searching an Array for a Range Match

Searching an Array for a Range Match

25
Q

What is this an example of?

  • Requires very large array; uses a lot of memory
  • Stores same value repeatedly
  • How do you know you have enough elements?
  • Customer can always order more

Searching an Array for a Range Match

A

Drawbacks of first approach

Searching an Array for a Range Match

26
Q

What is this an example of?

  • Create four discount array elements for each discount rate
  • Parallel array with discount range
  • Use loop to make comparisons

Searching an Array for a Range Match

A

Better approach

Searching an Array for a Range Match

27
Q

What is this an example of?

  • Every array has finite size
  • Number of elements in the array
  • Number of bytes in the array
  • Arrays composed of elements of same data type
  • Elements of same data type occupy same number of bytes in memory
  • Number of bytes in an array is always a multiple of number of array elements
  • Access data using subscript containing a value that accesses memory occupied by the array

Remaining within Array Bounds

A

Remaining within Array Bounds

Remaining within Array Bounds

28
Q

What is this an example of?

Program logic assumes every number entered by the user
is valid
When blank is used:
* Some languages stop execution and issue an error
* Other languages access a memory location outside of
the array

Remaining within Array Bounds

A

Invalid subscript

Remaining within Array Bounds

29
Q

True or False

Invalid array subscript is a logical error
Out of bounds: using a subscript that is not within the
acceptable range for the array
Program should prevent bounds errors

Remaining within Array Bounds

A

True

Remaining within Array Bounds

30
Q

What is this an example of?

A single statement
Initializes loop control variable
Compares it to a limit
Alters it

Using a for Loop to Process Arrays

A

For Loop

Using a for Loop to Process Arrays

31
Q

What is this an example of?

This loop is especially convenient when working with arrays
To process every element
Must stay within array bounds
Highest usable subscript is one less than array size

Using a for Loop to Process Arrays

A

For Loop

Using a for Loop to Process Arrays