Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

CS Grade 9-12

CS: Arrays and Lists

Storing, accessing, and updating ordered data

View Answer Key

Practice using arrays and lists to store ordered values, access elements by index, update data, and reason about common algorithms.

Read each problem carefully. Show your work in the space provided. Assume indexes start at 0 unless the problem says otherwise.

Name:
Date:
Score: / 12

Storing, accessing, and updating ordered data

CS - Grade 9-12

Instructions: Read each problem carefully. Show your work in the space provided. Assume indexes start at 0 unless the problem says otherwise.
  1. 1
    Five list cells with the third cell highlighted.

    A list named scores stores the values [88, 92, 75, 100, 67]. What value is stored at index 2? Explain how you found it.

  2. 2
    A four-cell color list changing from blue in the second cell to purple.

    A list named colors starts as ["red", "blue", "green", "yellow"]. After the statement colors[1] = "purple", what is the list?

  3. 3
    Six list cells with the first and last cells selected and combined.

    A program has the list nums = [4, 8, 15, 16, 23, 42]. Write the value of nums[0] + nums[5] and explain your answer.

  4. 4

    A list named names contains 6 elements. What are the valid index values for this list if the language uses 0-based indexing?

  5. 5
    Contiguous array cells compared with separated linked list nodes.

    Explain the difference between an array and a list in many programming languages. Include one example of when a list may be easier to use.

  6. 6
    A new cell being appended to the end of a three-cell list.

    A list starts as [10, 20, 30]. A program appends 40 to the list. What is the list after the append operation?

  7. 7
    The third cell is removed from a four-cell list and later cells shift left.

    A list named letters starts as ["a", "b", "c", "d"]. A program removes the element at index 2. What is the list after the removal?

  8. 8
    List elements flowing into an accumulator during a loop.

    Trace this loop and write the final value of total: nums = [3, 5, 2, 10]; total = 0; for each n in nums: total = total + n.

  9. 9

    Write pseudocode that prints every element in the list temperatures = [72, 68, 75, 70].

  10. 10

    A list named values is [9, 1, 6, 3]. Write pseudocode to find the largest value in the list.

  11. 11
    A pointer tries to access beyond the end of a ten-cell list.

    A program tries to access items[10] when items has length 10. Explain the error.

  12. 12

    A list of test scores is [80, 95, 70, 100, 85]. Write pseudocode to count how many scores are at least 90.

LivePhysics™.com CS - Grade 9-12

More CS Worksheets

See all CS worksheets

More Grade 9-12 Worksheets

See all Grade 9-12 worksheets