- Published on
- · July 10, 2026
Data Structures: Arrays, Stacks, Queues, Trees, and Hash
- Blog

- Henrico Piubello
- Henrico Piubello
- IT Specialist - Grupo Voitto
IT Specialist - Grupo Voitto
Data structures are formats for organizing information in a program''s memory, used to store, access, and manipulate data efficiently. Arrays, lists, stacks, queues, trees, graphs, and hash tables solve problems of collection, processing order, hierarchy, and fast lookup.

- What are data structures?
- Which data structure to use in each situation?
- What is the difference between an array and a list?
- Stacks and queues: LIFO and FIFO in practice
- Trees: hierarchy in parent and child nodes
- What are graphs for?
- How do hash tables work?
- Conclusion
What are data structures?
Data structures are standardized ways of storing and organizing values in memory, so that operations like search, insertion, and removal run in the shortest possible time. While a variable holds a single piece of data, a data structure defines how several pieces of data relate to each other — and that choice determines the software''s speed and memory consumption.
Data structures form, together with algorithms, the foundation of programming logic: there is no efficient program without a conscious decision about how the data will be stored. The topic''s relevance stays high: the Stack Overflow Developer Survey 2025 shows JavaScript as the most used language, by 66% of developers, and SQL by 59% — and both depend directly on arrays, trees, and hash tables in their interpreters and query engines.
Which data structure to use in each situation?
The choice of data structure depends on two questions: how the data needs to be accessed and how often it changes. Collections of known size call for arrays; constant insertions call for linked lists; processing order calls for stacks or queues; hierarchies call for trees; network relationships call for graphs; and key-based lookup calls for hash tables.
| Structure | How it organizes data | Typical use |
|---|---|---|
| Array | Fixed sequence, index-based access | Collections of known size |
| Linked list | Chained nodes, dynamic size | Frequent insertions and removals |
| Stack | LIFO: last in is first out | Function calls, undo |
| Queue | FIFO: first in is first out | Task and print queues |
| Tree | Hierarchy of parent and child nodes | Database indexes |
| Graph | Nodes connected by edges | Social networks, map routes |
| Hash table | Key-value pairs via hash function | Caches, dictionaries, indexes |
The table above summarizes the practical criterion: identify the dominant access pattern of your problem and pick the structure whose main operation is the cheapest for that pattern.
What is the difference between an array and a list?
An array is an ordered collection of elements of the same type, with a fixed size and direct index-based access — ideal when the number of items is known in advance. A list is a flexible collection that grows and shrinks at runtime through chained nodes, as in singly and doubly linked lists.
In practice, modern languages blur that boundary. In JavaScript, the Array object documented on MDN already behaves like a dynamic list, resizing itself automatically. In Python, the list type from the official documentation works the same way — and the CodeCrush Python guide shows these lists with code examples for beginners.
The conceptual difference, however, still matters: contiguous arrays offer constant-time reads and make better use of the processor cache, while linked lists let you insert and remove elements in the middle of the collection without reallocating the whole memory block.
Stacks and queues: LIFO and FIFO in practice
Stacks and queues are specialized structures that control the order of access to elements: it is not only what is stored that matters, but who enters and who leaves first. Each has specific insertion and removal operations that follow a fixed logic.
Stack: works on the LIFO principle (Last In, First Out). Elements are always added and removed from the top. The stack is used in function call management (the call stack), the undo button in editors, and browser history navigation.
Queue: works on the FIFO principle (First In, First Out). Elements enter at the end and leave from the front. The queue is used in print queues, background task processing, and messaging systems, where the order of arrival must be respected.
Trees: hierarchy in parent and child nodes
Trees are hierarchical structures made of interconnected nodes starting from a root node, in parent and child relationships. Trees appear in database indexes, file systems, interfaces (the DOM is a tree), and the decision models used in machine learning.
A practical example is the decision tree, where each node represents a test on an attribute:
Árvore de decisão:
Atributo X <= 30?
/ \
Sim Não
| |
Tomate Maçã
In this example:
- The root node asks whether attribute X is less than or equal to 30.
- If the answer is yes, the path follows to the left node, classified as tomato.
- If the answer is no, the path follows to the right node, classified as apple.
This mechanic of chained decisions explains why trees dominate classification and forecasting in data science. The weight of these areas only grows: in the Octoverse 2024 report, GitHub recorded that Python overtook JavaScript as the platform''s most used language, driven by AI (Artificial Intelligence) and data science, and that the use of Jupyter Notebooks grew 92% in a year.
What are graphs for?
Graphs serve to model relationships between entities: they are sets of nodes connected by edges, capable of representing any network — friendships on social networks, routes between cities, dependencies between software packages, or links between web pages.
A friendship graph illustrates the idea. Consider three friends: Renata, Carol, and Maria.
Grafo de amizades:
Renata —— Carol
|
Maria
In this example:
- Renata is friends with Carol (edge Renata—Carol).
- Renata is also friends with Maria (edge Renata—Maria).
- Carol and Maria have no direct edge: the connection between them goes through Renata.
In a real social network, this graph grows to millions of nodes and edges, and other relationship types — "follows", "works with" — become new edges. Shortest-path and recommendation algorithms traverse exactly this structure to suggest friends, compute routes, and rank content.
How do hash tables work?
Hash tables work by applying a hash function to each item''s key to calculate the position where the value is stored. This direct calculation allows searching, inserting, and removing in average constant time, regardless of the table''s size — which is why they support caches, indexes, and the native dictionaries of several languages.
Suppose a banking system that stores customer information and needs to speed up lookup:
Tabela hash de clientes:
+---------------+---------------------------------------------+
| Chave | Valor |
+---------------+---------------------------------------------+
| 123456 | Nome: Renata, Saldo: 5000, Tipo: Premium |
| 987654 | Nome: Carol, Saldo: 3000, Tipo: Regular |
| 555555 | Nome: Maria, Saldo: 8000, Tipo: Premium |
+---------------+---------------------------------------------+
When looking up the customer with ID 123456, the hash function directly calculates the record''s position in the table, without traversing the others — a direct access that does not degrade as the base grows.
Hash tables must handle collisions, situations in which two different keys produce the same hash value. The classic techniques are chaining (each position holds a small list of items) and probing (the item looks for the next free position). Python dictionaries, described in the official data structures documentation, implement exactly this key-value mapping mechanism.
Conclusion
Mastering data structures is the investment with the best technical return in a programmer''s career: it is what separates code that merely works from code that scales. Before writing the next function, it is worth asking which structure best represents the problem — swapping a linear search on a list for a hash table, or an improvised hierarchy for a tree, usually yields performance gains of orders of magnitude without rewriting the system.
## faq
Frequently asked questions
What are data structures for?
Data structures serve to organize information in memory so the program can store, search, and modify data efficiently. The right choice reduces execution time and memory consumption: an array accesses by index in constant time, while a hash table locates values by key almost instantly.
What is the difference between a stack and a queue?
A stack follows the LIFO principle: the last element inserted is the first removed, as in function calls and the undo button. A queue follows FIFO: the first element inserted is the first served, as in print queues and task processing. The difference lies in the order of element removal.
Array or linked list: which to choose?
Choose an array when the collection size is known and index-based access is frequent, since reading happens in constant time. Prefer a linked list when there are many insertions and removals in the middle of the collection, since it grows dynamically without reallocating all elements in memory.
What is a hash table and where is it used?
A hash table is a structure that maps keys to values using a hash function to calculate each item''s position. It allows search, insertion, and removal in average constant time. It is used in database indexes, caches, Python dictionaries, and JavaScript objects.
Is it worth studying data structures in 2026?
Yes. Data structures remain the basis of technical interviews and efficient system development, including AI (Artificial Intelligence) applications that depend on arrays and tensors. Mastering arrays, stacks, queues, trees, and hash tables differentiates candidates and improves the quality of any code.
Topics in this article
## continue lendo
Artigos relacionados
Keep browsing
Previous article

Euclidean Distance: What It Is, Formula, and Uses in Python
Euclidean distance is the straight-line measure between two points, obtained by the root of the sum of squared differences; it is the basis of KNN and K-Means.
Read moreNext article

Why Do Nerds Like Programming? Passion and Code
Nerds like programming because it unites logic, problem solving and creation — and 68% of developers code as a hobby outside of work.
Read moreAbout the author



