For algorithms involving elements of a list: a. Write iteration statements to traverse a list. b. Determine the result of an algorithm that includes list traversals.

AAP-2.O.1 Traversing a list can be a complete traversal, where all elements in the list are accessed, or a partial traversal, where only a portion of elements are accessed.

AAP-2.O.2 Iteration statements can be used to traverse a list.

AAP-2.O.3 The exam reference sheet provides

Text:

FOR EACH item IN aList
{
 <block of statements>
}

Block:

FOR EACH item IN aList
   block of statements

The variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The code in block of statements is executed once for each assignment of item.

AAP-2.O.4 Knowledge of existing algorithms that use iteration can help in constructing new algorithms. Some examples of existing algorithms that are often used with lists include:

  • determining a minimum or maximum value in a list
  • computing a sum or average of a list of numbers

AAP-2.O.5 Linear search or sequential search algorithms check each element of a list, in order, until the desired value is found or all elements in the list have been checked.