Set
- Core set-theoretical operations
union(S,T)
- returnintersection(S,T)
- returndifference(S,T)
- returnsubset(S,T)
- return true if
- Typical operations that may be provided by a static set structure are:
member(S,x)
- return true ifis-empty(S)
- return true ifsize(S)
returnbuild-set(x_1,x_2,...,x_n)
create a set from the elements- and others
- A dynamic set typically adds the dynamic set operations
- dictionary operations (insert, delete, search)
- minimun, maximum, successor, predecessor
Stack
- LIFO
Operation | |
---|---|
Push(S,x) | add an element to the collection |
Pop(S) | remove the most recently added element |
(optional) Peek(S) (or Top(S) | return the most recently added element element |
(optional) Stack-empty(S) |
- implementations:
- array
- linked list
Queue
- FIFO
Operation | desc | |
---|---|---|
enqueue(Q,x) | g | |
dequeue(Q) | ||
queue-empty(Q) | ||
queue-full(Q) |
Double-Ended Queue (Deque)
desc | ||
---|---|---|
head-enqueue(Q,x) | g | |
tail-enqueue(Q,x) | g | |
head-dequeue(Q) | ||
tail-dequeue(Q) |
Priority Queue
Operation | |
---|---|
insert(Q,x) | Add an element x with a priority |
extract-max(Q) (or extract-min(Q) ) | Remove and return the element with the highest (lowest) priority |
peek-max(Q) (or peek-min(Q) ) | Return the element with the highest (lowest) priority |
- implementions:
- binary heap (most common)
- fibonacci heap (more advanced, better theoretical performance)
- and others
Graph
- A graph is an ADT that is meant to implement the undirected and directed graphs concepts from graph theory
Graph Representation
- A sparse graph is a graph with edges. A dense graph is a graph with edges.
- is a graph with vertices and edges.
- An adjacency matrix is a matrix where if and otherwise.
- If is undirected, the adjacency matrix is symmetric.
- The adjacency matrix representation allows us to check in time if a given edge is in the graph
- The adjacency matrix representation requires space. (when the graph has many fewer edges than , more compact representations are possible)
- Many graph algorithms need to examine all the edges connected to a given vertex . In the worst case, may have neighbors. However, this case is rare in practice.
- An adjacency list is an array
Adj
of records, whereAdj[i]
contains all the vertices such that .- The length of
Adj[v]
is the degree of vertex and is denoted by . - In an undirected graph, each edge appears twice. the node appears in
Adj[i]
and the node appears inAdj[j]
. - Adjacency lists are a more compact representation of sparse graphs.
- Adjacency lists require space
- The length of
- An adjacency matrix is a matrix where if and otherwise.
Adjacency Matrix | Adjacency List | |
---|---|---|
Space | ||
Check if |