# Data structure

> A way of organizing data in memory so the operations you need are fast.

- Level: Intermediate
- Topics: Software, Data
- URL: https://tidbit.legios.com.ar/data-structure/
- In Spanish: [Estructura de datos](https://tidbit.legios.com.ar/es/data-structure/)

A **data structure** is a particular way of arranging data inside a program so it can be used efficiently. The same list of customers can be kept as a simple numbered row, sorted, grouped by city or linked in a chain, and each arrangement makes some operations fast and others slow. Choosing the right one is half of writing a good algorithm.

A few classics show up everywhere. An **array** is a row of numbered slots: jumping to slot 500 is instant, but inserting in the middle means shifting everything after it. A **hash table** (called a dictionary or map in many languages) finds a value by its key almost instantly, like looking up a phone number by name. A **stack** works like a pile of plates, last in first out, and is how programs remember which function called which. A **queue** is first in first out, like a line at the bank, and is used for jobs waiting their turn. **Trees** and **graphs** connect items to each other, for folders inside folders, database indexes or a map of roads.

You rarely build these from scratch: every modern language ships with good versions of them. What matters is knowing which to pick. Searching for a name in an unsorted list of a million entries means checking them one by one; putting the same names in a hash table makes each lookup take about the same time no matter how big it grows.

## An analogy

How you organize a kitchen. Spices on a rack by name, plates in a stack, the shopping list in order of the supermarket aisles: same stuff, arranged for how you use it.

## Keep in mind

- The arrangement decides which operations are fast and which are slow.
- Classics: array, hash table, stack, queue, tree, graph.
- Languages include ready-made versions; the skill is choosing well.
- Hash tables give near-instant lookup by key, even with huge amounts of data.

## Go deeper

- [Data structure on Wikipedia](https://en.wikipedia.org/wiki/Data_structure)
- [Data structures (official Python tutorial)](https://docs.python.org/3/tutorial/datastructures.html)

## Related terms

- [Algorithm](https://tidbit.legios.com.ar/algorithm/): A precise, step-by-step method for solving a problem or doing a task.
- [Hashing](https://tidbit.legios.com.ar/hashing/): A one-way fingerprint of data: easy to compute, not meant to be reversed.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Database index](https://tidbit.legios.com.ar/database-index/): A sorted shortcut that lets a database find rows without reading the whole table.
