๐6.4: Array Algorithms
Table of Contents
๐ This page is a condensed version of CSAwesome Topic 6.4
Array Algorithms (FRQs)
In this lesson, you will study different Free Response Questions and responses that develop algorithms using arrays.
Here are some common algorithms that you should be familiar with for the AP CSA exam:
- ๐ Searching Algorithms:
- Determine the minimum value in an array
- Determine the maximum value in an array
- Search for a specific element in the array
- โ Acculumator Patterns:
- Compute a sum of array elements
- Compute an average of array elements
- Determine the number of elements meeting specific criteria
- ๐งช Testing Properties:
- Determine if at least one element has a particular property
- Determine if all elements have a particular property
- Determine the presence (or absence) of duplicate elements
- โ๏ธ Manipulating Array Order:
- Shift/Rotate elements to the left or right
Requires keeping track of the current INDEX!
- Reverse the order of the elements
Requires keeping track of the current INDEX!
- Shift/Rotate elements to the left or right
๐ There are two common array traversal loops that can be used for these algorithms.
- Enhanced for (for-each) loops visit EVERY ITEM in sequential order:
for (int value : array) { if (value ....) { ... } }
- Standard for loops keep track of the current INDEX โ offering more flexibility (modify values, traversing in different order, etc):
for (int i=0; i < array.length; i++) { if (array[i] ....) { ... } }
๐ป In-Class Activity: Array Algorithms
Acknowledgement
Content on this page is adapted from Runestone Academy - Barb Ericson, Beryl Hoffman, Peter Seibel.