Arrays (Cambridge (CIE) A Level Computer Science): Flashcards

Exam code: 9618

1/41

0Still learning

Know0

  • Define array.

Cards in this collection (41)

  • Define array.

    An array is an ordered, static set of elements that can store only one data type.

  • How is the position of each element in an array identified?

    By the array's index.

  • An array is an ordered,              set of elements.

    An array is an ordered, static set of elements.

  • True or False?

    An array can store more than one data type.

    False.

    An array can store only one data type.

  • Define lower bound (LB).

    The lower bound is the array's first element.

  • Define upper bound (UB).

    The upper bound is the array's last element.

  • What is the lower bound of an array typically?

    Typically 0 or 1, depending on the language being used.

  • A one-dimensional array is also called a              array.

    A one-dimensional array is also called a linear array.

  • What must be included when declaring a 1D array in pseudocode?

    The lower bound, the upper bound and the data type.

  • What is the pseudocode syntax for declaring a 1D array?

    DECLARE <identifier> : ARRAY[LB:UB] OF <data type>

  • Write pseudocode to declare a 1D array of five single characters called Letters.

    DECLARE Letters : ARRAY[0:4] OF CHAR

  • True or False?

    ARRAY[0:4] holds four elements.

    False.

    It holds five elements, because the lower bound and upper bound are both included: indices 0, 1, 2, 3 and 4.

  • Write pseudocode to assign the character 'B' to the first element of Letters.

    Letters[0] ← 'B'

  • How can a 2D array be visualised?

    As a table.

  • How do you navigate through a 2D array?

    First go down the rows, then across the columns, to find a position within the array.

  • Which four bounds must be declared for a 2D array?

    The lower and upper bounds for rows (LBR and UBR), and the lower and upper bounds for columns (LBC and UBC).

  • What is the pseudocode syntax for declaring a 2D array?

    DECLARE <identifier> : ARRAY[LBR:UBR, LBC:UBC] OF <data type>

  • How many rows and columns does ARRAY[0:2, 0:4] create?

    3 rows and 5 columns.

  • In a 2D array reference, which index comes first?

    The row comes first, then the column, written as Identifier[row, column].

  • Define linear search.

    A linear search starts with the first value in a dataset and checks every value one at a time until all values have been checked.

  • True or False?

    A linear search requires the data to be in order.

    False.

    A linear search can be performed even if the values are not in order.

  • In which order are elements checked in a linear search on an array?

    In order from the lower bound to the upper bound, until the item is found or the upper bound is reached.

  • What are the four steps of a linear search?

    Check the first value. IF it is the value you are looking for, STOP. ELSE move to the next value and check. REPEAT UNTIL all values have been checked.

  • In the linear search example, what does the identifier Found store?

    A BOOLEAN that tracks whether the target value has been found.

  • In the linear search example, what does the identifier Index store?

    The current position being checked in the array.

  • In the linear search, Found is initialised to            before the loop begins.

    In the linear search, Found is initialised to FALSE before the loop begins.

  • Write the pseudocode condition that controls the linear search loop.

    WHILE Index <= 4 AND Found = FALSE DO

  • Why does the linear search use a WHILE loop rather than a FOR loop?

    For flexibility, because a WHILE loop allows an early exit as soon as the item is found.

  • In the linear search, what happens to Index when the current element does not match the target?

    Index ← Index + 1, which moves the search on to the next position.

  • Define bubble sort.

    A bubble sort checks values in pairs, starting at the beginning of a dataset, and swaps them if they are not in the correct order.

  • Define pass in a bubble sort.

    A pass is one full run of comparisons from the beginning to the end of the dataset.

  • When is a bubble sort finished?

    When there are no more swaps to make.

  • What are the steps of a bubble sort?

    Compare the first two values. IF they are in the wrong order, swap them. Compare the next two values and repeat to the end of the dataset. IF any swaps were made, repeat from the start. ELSE stop, because the list is in the correct order.

  • A bubble sort starts with the dataset 5 2 4 1 6 3.

    What is the dataset after pass 1?

    2 4 1 5 3 6

  • A bubble sort starts with the dataset 5 2 4 1 6 3.

    How many passes are needed?

    Four passes. Passes 1, 2 and 3 make swaps, and pass 4 makes no swaps, which confirms the list is sorted.

  • In the bubble sort pseudocode, what is the purpose of the Swapped variable?

    It indicates whether a swap occurred during a pass, and is used to optimise the sort by leaving the loop early.

  • If no swaps were made on a pass, the bubble sort uses          to leave the loop early.

    If no swaps were made on a pass, the bubble sort uses EXIT to leave the loop early.

  • In the bubble sort pseudocode, what is the purpose of the Temp variable?

    It is a temporary variable used for swapping two elements in the array.

  • Write the three pseudocode lines that swap two adjacent array elements.

    Temp ← Numbers[Index], then Numbers[Index] ← Numbers[Index + 1], then Numbers[Index + 1] ← Temp

  • Write the comparison condition used in the bubble sort loop.

    IF Numbers[Index] > Numbers[Index + 1] THEN

  • True or False?

    In the bubble sort example the inner loop runs from 0 to 5.

    False.

    The inner loop runs FOR Index ← 0 TO 4. It compares Numbers[Index] with Numbers[Index + 1], so going as far as 5 would read past the upper bound of the array.

Sign up to unlock flashcards

or