๐Ÿ““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!

๐Ÿ” There are two common array traversal loops that can be used for these algorithms.

  1. Enhanced for (for-each) loops visit EVERY ITEM in sequential order:
      for (int value : array) {
       if (value ....) {
           ...
       }
      }
    
  2. 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

  1. Go to
  2. Make sure you SIGN IN!
  3. Complete all Coding Exercises in groups.

Acknowledgement

Content on this page is adapted from Runestone Academy - Barb Ericson, Beryl Hoffman, Peter Seibel.