---
description: "Computer science data structure visualization in draw.io — arrays, linked lists, trees, graphs, hash tables, heaps, stacks, queues"
triggers:
- data structure
- array diagram
- linked list
- binary tree
- hash table
- graph visualization
- stack queue
- heap
- trie
- b-tree
globs:
- "**/*.drawio"
- "**/*.drawio.svg"
---
# Data Structure Diagrams
## Quick Reference
| Structure | Best For | Complexity |
|-----------|----------|------------|
| Array | Sequential data, index access | Low |
| Linked List | Insertion/deletion demos | Low |
| Stack | LIFO operations, call stacks | Low |
| Queue | FIFO operations, BFS | Low |
| Binary Tree | Hierarchical data, BST | Medium |
| AVL / Red-Black Tree | Balanced search demos | Medium |
| B-Tree | Database index visualization | High |
| Heap | Priority queue, heapsort | Medium |
| Hash Table | Key-value mapping, collisions | Medium |
| Graph | Networks, relationships, paths | Medium-High |
| Trie | Prefix search, autocomplete | Medium |
---
## Shared Style Constants
```
Cell colors:
Default: fillColor=#DAE8FC;strokeColor=#6C8EBF; (blue)
Highlight: fillColor=#D5E8D4;strokeColor=#82B366; (green — active/found)
Alert: fillColor=#F8CECC;strokeColor=#B85450; (red — removed/error)
Visited: fillColor=#FFF2CC;strokeColor=#D6B656; (yellow — traversed)
Empty: fillColor=#F5F5F5;strokeColor=#CCCCCC; (gray — null/empty)
Text: fontColor=#333333;fontSize=14;fontFamily=Consolas;
Index: fontColor=#999999;fontSize=10;fontStyle=2; (italic, small)
Arrow: strokeColor=#666666;strokeWidth=2;endArrow=block;endFill=1;
```
---
## Arrays
### Linear Array
```xml
```
### 2D Matrix
Use a grid of cells. Each row shares the same Y, each column the same X. Add row/column headers with index labels.
```xml
```
---
## Linked Lists
### Singly Linked List
Each node has a data cell and a pointer cell side by side:
```xml
```
### Doubly Linked List
Same as above but add a second pointer cell on the left of each node, and backward arrows.
---
## Stacks and Queues
### Stack (LIFO)
Vertical arrangement, top item highlighted:
```xml
```
### Queue (FIFO)
Horizontal arrangement with front/rear labels:
```xml
```
---
## Binary Trees
### Binary Search Tree
```xml
```
### Node Style Variants
| Type | Style | Use |
|------|-------|-----|
| Default node | `ellipse;fillColor=#DAE8FC;strokeColor=#6C8EBF;` | Unvisited |
| Current / found | `ellipse;fillColor=#D5E8D4;strokeColor=#82B366;` | Highlight during traversal |
| Removed | `ellipse;fillColor=#F8CECC;strokeColor=#B85450;dashed=1;` | Deleted node |
| Null leaf | `ellipse;fillColor=#F5F5F5;strokeColor=#CCCCCC;fontColor=#CCCCCC;` | NIL sentinel |
### AVL Tree Annotations
Add balance factor as a superscript label above each node:
```xml
```
---
## Heaps
### Min-Heap (Array-backed tree)
Show both the tree view and the underlying array. Use the same node IDs so the relationship is clear.
Tree layout is identical to BST above. Below the tree, add the array view:
```xml
```
---
## Hash Tables
### Separate Chaining
```xml
```
### Open Addressing (Linear Probing)
Use a single row of cells (like an array) with color coding:
| Color | Meaning |
|-------|---------|
| Blue (`#DAE8FC`) | Occupied — hashed to this index |
| Yellow (`#FFF2CC`) | Occupied — probed to this index (collision) |
| Gray (`#F5F5F5`) | Empty slot |
| Red (`#F8CECC`) | Tombstone (deleted) |
---
## Graphs
### Directed Graph (Adjacency Visualization)
```xml
```
### Undirected Graph
Same as directed but use `endArrow=none;startArrow=none;` on edges.
### Graph Traversal Coloring
Show BFS/DFS state with node colors:
| State | Fill | Meaning |
|-------|------|---------|
| Unvisited | `#DAE8FC` (blue) | Not yet discovered |
| In queue/stack | `#FFF2CC` (yellow) | Discovered, not processed |
| Processing | `#D5E8D4` (green) | Currently visiting |
| Completed | `#E6E6E6` (gray) | Fully processed |
---
## Tries
### Prefix Trie
```xml
```
Green nodes (`#D5E8D4`) mark word endings (`isEnd=true`).
---
## Layout Tips
1. **Consistent spacing** — Use 8px grid; tree levels at 80-100px vertical intervals
2. **Color meaning** — Pick a legend and stick to it (blue=default, green=active, red=removed, yellow=visited)
3. **Monospace font** — Always `fontFamily=Consolas;` for data values
4. **Index labels** — Use small italic gray text above/below cells
5. **Pointer arrows** — `strokeWidth=2;endArrow=block;endFill=1;` for linked structures
6. **Animation frames** — Use draw.io pages for step-by-step algorithm visualization (page 1: initial, page 2: step 1, etc.)
7. **Null sentinels** — Gray fill, dashed stroke, `null` or `∅` text