Built-ins › Data Structuresv0.1
Built-ins

Data Structures

Interview-ready data structures built into Pseudo. Auto-print shows a visual representation when you print them.

Stack

pseudo
s = Stack()
push(s, 1)
push(s, 2)
push(s, 3)
s
Output
Stack (top → bottom): [ 3 ] ← top [ 2 ] [ 1 ]
MethodDescription
push(stack, item)Add item to top
pop(stack)Remove and return top item
peek(stack)View top item without removing
isEmpty(stack)True if empty
size(stack)Number of elements

Queue

pseudo
q = Queue()
enqueue(q, "a")
enqueue(q, "b")
enqueue(q, "c")
q
Output
Queue (front → back): front → [ "a" ] [ "b" ] [ "c" ] ← back
MethodDescription
enqueue(queue, item)Add item to back
dequeue(queue)Remove and return front item
peek(queue)View front item without removing
isEmpty(queue)True if empty
size(queue)Number of elements

HashMap

pseudo
m = HashMap()
m.put("name", "Alice")
m.put("age", 25)
m
Output
HashMap: "name" → "Alice" "age" → 25
pseudo
# Also works with dict-style:
m = {}
m["name"] = "Alice"
print m.get("name")   # → Alice
print m.has("age")    # → false
print m.keys()        # → ["name"]
MethodDescription
map.put(key, value)Insert or update key-value pair
map.get(key)Get value by key (null if not found)
map.has(key)True if key exists
map.remove(key)Delete key-value pair
map.keys()List of all keys
map.values()List of all values
map.size()Number of entries

Set

pseudo
s = Set()
s.add(1)
s.add(2)
s.add(2)  # duplicate ignored
s
Output
Set: {1, 2}
pseudo
a = Set([1,2,3])
b = Set([2,3,4])
a.union(b)         # → Set: {1, 2, 3, 4}
a.intersection(b)  # → Set: {2, 3}
a.difference(b)    # → Set: {1}
MethodDescription
s.add(item)Add item (duplicate ignored)
s.has(item)True if item in set
s.remove(item)Remove item
s.size()Number of elements
s.union(other)Return union of two sets
s.intersection(other)Return intersection
s.difference(other)Return difference

MinHeap / MaxHeap

pseudo
pq = MinHeap()
push(pq, 5)
push(pq, 1)
push(pq, 3)
peek(pq)    # → 1 (min on top)
pop(pq)     # → 1
pop(pq)     # → 3
MethodDescription
push(heap, item)Add item
pop(heap)Remove and return min/max
peek(heap)View min/max without removing
size(heap)Number of elements
isEmpty(heap)True if empty

TreeNode

pseudo
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root
Output
1 2 3 4
AttributeDescription
node.valThe node value
node.leftLeft child (null by default)
node.rightRight child (null by default)

ListNode (Linked List)

pseudo
head = linkedList([1, 2, 3, 4])
head
Output
1 → 2 → 3 → 4 → null
pseudo
# Manual construction:
head = ListNode(1)
head.next = ListNode(2)
head.next.next = ListNode(3)
Attribute / FunctionDescription
node.valThe node value
node.nextNext node (null if end)
linkedList(list)Build linked list from a list, returns head

Graph

pseudo
g = Graph()
g.addEdge(1, 2)
g.addEdge(1, 3)
g.addEdge(2, 4)
g
Output
Graph: 1 → [2, 3] 2 → [1, 4] 3 → [1] 4 → [2]
MethodDescription
g.addVertex(v)Add vertex
g.addEdge(u, v)Add undirected edge
g.addEdge(u, v, weight)Add weighted edge
g.neighbors(v)List of adjacent vertices
g.hasEdge(u, v)True if edge exists
g.vertices()List of all vertices