- Home
- /
- Computational Thinking
- /
- Computational Thinking
- /
- Array
An ordered collection of values stored together under a single name and accessed by their numeric index position. Arrays are essential for handling lists, sequences, and collections of data.
Definition
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.
π‘ Intuition
A numbered list. Item 0, item 1, item 2... Access any by its number.
π― Core Idea
Arrays store multiple related values under one name, making it easy to iterate over them all.
Example
π Why It Matters
Arrays are essential for handling lists, sequences, and collections of data. Nearly every real program works with arraysβstudent grades, shopping cart items, search results, and pixel colors in images are all stored in arrays.
π Hint When Stuck
When working with arrays, remember that indices start at 0 in most languages, so the last element of an array with n items is at index n-1. Use loops to process every element, and always check that your index is within bounds before accessing an element.
Formal View
Related Concepts
π§ Common Stuck Point
Most languages index from 0, not 1. The last element of a 3-item array is at index 2.
β οΈ Common Mistakes
- Accessing an index that is out of bounds (e.g., index 5 in a 5-element array, which only has indices 0-4)
- Forgetting that arrays are zero-indexed, leading to off-by-one errors
- Confusing the array length with the last valid index (length 5 means last index is 4)
Frequently Asked Questions
What is Array in CS Thinking?
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.
When do you use Array?
When working with arrays, remember that indices start at 0 in most languages, so the last element of an array with n items is at index n-1. Use loops to process every element, and always check that your index is within bounds before accessing an element.
What do students usually get wrong about Array?
Most languages index from 0, not 1. The last element of a 3-item array is at index 2.
Prerequisites
How Array Connects to Other Ideas
To understand array, you should first be comfortable with variable and data types. Once you have a solid grasp of array, you can move on to iteration, searching and sorting.
π» Animated Visualization Animated
Access elements by their index position