Data structures, seeing them work

Stack, queue, linked list and hash table with animations: press push, pop, enqueue... and watch what happens.

A data structure is a way of organising information so that certain operations are fast. Choosing the right structure usually matters more than optimising the code.

Visualiser

Elige una estructura, escribe un valor (o déjalo vacío para uno al azar) y pulsa las operaciones:

Which to use and when

Your language already has them

// JavaScript
const pila = [];      pila.push(x);   pila.pop();
const cola = [];      cola.push(x);   cola.shift();
const mapa = new Map(); mapa.set(k, v); mapa.get(k); mapa.has(k);
const conjunto = new Set();  conjunto.add(x);  conjunto.has(x);
# Python
pila = [];            pila.append(x);  pila.pop()
from collections import deque
cola = deque();       cola.append(x);  cola.popleft()
mapa = {};            mapa[k] = v;     mapa.get(k);   k in mapa
conjunto = set();     conjunto.add(x); x in conjunto
// Java
Deque<Integer> pila = new ArrayDeque<>();  pila.push(x);   pila.pop();
Queue<Integer> cola = new LinkedList<>();   cola.add(x);    cola.poll();
Map<String,Integer> mapa = new HashMap<>(); mapa.put(k,v);  mapa.get(k);
Set<Integer> conjunto = new HashSet<>();    conjunto.add(x); conjunto.contains(x);

Check what you've learned

Next step

Big-O y complejidad · Recursion · Data structures in Java