Introduction to Data Structures
Grouping many values together, so a program can handle collections of data
- say what a data structure is in simple words,
- explain how a list (also called an array) groups many values,
- use the words item, position, and length to talk about a list.
1. One value is not always enough
Imagine a program that remembers your friend's name. It can keep one value in one labelled box, like friend = "Sara". That is fine for one thing.
But what if you have thirty friends? Making thirty separate boxes — friend1, friend2, friend3, all the way to friend30 — would be slow, messy, and easy to get wrong. There must be a tidier way to keep many values that belong together. There is: we group them.
2. What is a data structure?
A data structure is a way of organising data so a program can keep it tidy and find it easily. Just like a pencil case keeps your pens together, or a bookshelf keeps your books in order, a data structure keeps values together in a helpful shape.
The simplest and most useful data structure of all is the list. Many programming languages also call a list an array. A list holds many values in a row, one after another, all under a single name.