Practice Array in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

An ordered collection of values stored together under a single name and accessed by their numeric index position. Arrays allow you to store, retrieve, and manipulate multiple related values efficiently using loops and index-based access.

A numbered list. Item 0, item 1, item 2... Access any by its number.

Showing a random 20 of 50 problems.

Example 1

medium
Array `a = [10, 20, 30, 40, 50]`. What is `a[a[0]/10]`?

Example 2

hard
Linear search needs at most how many comparisons to find a value in an array of length nn (worst case)?

Example 3

medium
Array `a = [9, 7, 5, 3, 1]`. What is `a[len(a) - 1]`?

Example 4

medium
Given `scores = [12, 15, 9, 20]`, what are `scores[0]` and `scores[3]`, and what happens if code tries to read `scores[4]`?

Example 5

easy
Array `a = [3, 1, 4, 1, 5]`. After `a[1] = 9`, what is the array?

Example 6

medium
To insert a value at index 1 in an array of length 6 (no resize cost), how many existing elements must shift right?

Example 7

medium
Write pseudocode to count how many elements of `nums = [3, 7, 2, 9, 4]` are greater than 5. What is the count?

Example 8

medium
Array `a = [9, 3, 7, 1, 5]`. After ascending sort, what is `a[2]`?

Example 9

easy
Array `a = [11, 22, 33, 44, 55]`. What is `a[0]`?

Example 10

medium
Array `a = [3, 1, 4, 1, 5, 9]`. What is `a[1] + a[4]`?

Example 11

easy
Array `a = [4, 4, 4]`. What is the sum of all elements?

Example 12

medium
Sum every element of `a = [10, 20, 30, 40]` using indices 0 to length-1. What is the sum?

Example 13

medium
Fill in the blank: To loop over every element of an array of length nn, indices range from 0 to ____.

Example 14

medium
Array `a = [5, 3, 8, 1]`. After sorting ascending, what is `a[0]`?

Example 15

medium
Sum every element of `a = [3, 5, 7]` by looping indices 0 to length-1. What is the sum?

Example 16

easy
Array `a = [1, 2, 3]`. What happens with `a[3]`?

Example 17

easy
Array `a = [11, 22, 33, 44, 55]`. What is `a[4]`?

Example 18

hard
You want to swap the FIRST and LAST elements of an array of length 6 without overwriting either. What is the minimum number of assignments needed?

Example 19

medium
Reverse `a = [1, 2, 3, 4]` by swapping a[i] with a[n-1-i]. What is `a[3]` paired with for swapping when i=0?

Example 20

medium
Reverse `a = [1,2,3,4,5]` by swapping `a[i]` with `a[n-1-i]`. After processing i=0i=0 and i=1i=1, what is the array?