Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Every page on [the site](https://dnakhoa.github.io/everything-data-structures/)

**Worked examples.** Concrete traces through an algorithm, with real numbers, tend to teach better than prose.

**Exercises.** Every chapter ends with a `## Exercises` section. New exercises should follow the existing format: a bold number and difficulty (`**12.8 ★★ Title.**`), the question, then a `<details>` block with `<summary>Solution</summary>` (and optionally one for a hint before it). Leave a blank line after `<summary>...</summary>` and before `</details>`, or the Markdown inside won't render; CI checks this, and checks that exercises are numbered in order. Solutions should show the working, not just the answer, and any code in them should actually run.

**Real-world usage.** If you know a production system that uses a structure in a way the book doesn't mention, that's worth adding, especially with a link to source or a design doc.

## What to check before submitting
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A complete, free course on data structures, from asymptotic analysis and pointer

**📖 Read it online: [dnakhoa.github.io/everything-data-structures](https://dnakhoa.github.io/everything-data-structures/)**

Five volumes · 31 chapters · 4 appendices · ~55,000 words · Python, C, C++, Java and Go examples.
Five volumes · 31 chapters · 4 appendices · ~155,000 words · 225 exercises with worked solutions · Python, C, C++, Java and Go examples.

Written by [Ngoc Anh Khoa Doan](https://github.com/dnakhoa), with the editorial help of Claude.

Expand All @@ -21,7 +21,7 @@ Also by the author: **[Frontier LLM Engineering](https://github.com/dnakhoa/fron

Most data structure resources stop at red-black trees. This one keeps going, through competitive-programming machinery (link-cut trees, wavelet trees, Mo's algorithm), through research-grade structures (FM-indexes, succinct trees, fractional cascading), and out the other side into system design, where the central claim of Volume V is that **a routing table is a trie, consistent hashing is a hash ring, and a message queue is a persistent FIFO**. Systems are data structures composed at scale.

Every chapter covers the same ground: the idea, the invariants, the operations with complexity analysis, working code, real-world usage, and the historical context of who invented it and why.
Every chapter covers the same ground: the idea, the invariants, the operations with complexity analysis, working code, real-world usage, and the historical context of who invented it and why. Every chapter then ends with an exercise set (★ check your understanding, ★★ apply it, ★★★ stretch), each with a folded worked solution and, for the harder ones, a hint.

---

Expand Down Expand Up @@ -54,7 +54,7 @@ The structures that actually come up, plus the judgment to pick between them.
Track 1, then:

- [Chapter 8: Self-Balancing Trees](src/volume-1/ch08-self-balancing-trees.md). AVL, red-black, splay, treaps
- [Chapter 11: Graphs](src/volume-2/ch11-graphs-modeling-relationships.md). BFS/DFS, topological sort, MST, shortest paths, union-find
- [Chapter 11: Graphs](src/volume-2/ch11-graphs-modeling-relationships.md). BFS/DFS, cycle detection, topological sort, strongly connected components, union-find, MST, Dijkstra, Bellman-Ford and Floyd-Warshall
- [Chapter 13: String Data Structures](src/volume-2/ch13-string-data-structures.md). Tries, suffix arrays
- [Chapter 14: Probabilistic Data Structures](src/volume-3/ch14-probabilistic-data-structures.md). Bloom filters come up constantly
- [Chapter 25: Complete Selection Guide](src/volume-4/ch25-complete-selection-guide-and-complexity-reference.md). The decision matrix
Expand Down
1 change: 1 addition & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ create-missing = false

[output.html]
additional-css = ["theme/custom.css"]
additional-js = ["theme/print-details.js"]
default-theme = "rust"
preferred-dark-theme = "navy"
git-repository-url = "https://github.com/dnakhoa/everything-data-structures"
Expand Down
49 changes: 49 additions & 0 deletions scripts/check_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
3. Every chapter page starts with a single H1.
4. Code fences are balanced.
5. SVG files contain no blank lines (a blank line ends the raw-HTML block in Markdown).
6. Every chapter has an Exercises section, numbered for that chapter, and every
<details> hint/solution block is balanced and padded with the blank lines
mdBook needs to render the Markdown inside it.
"""
import ast
import glob
Expand Down Expand Up @@ -100,13 +103,59 @@ def check_svgs():
print(" svgs checked")


def check_exercises():
chapters = [p for p in iter_md() if re.match(r"ch\d+-", os.path.basename(p))]
total = 0
for path in chapters:
num = int(re.match(r"ch(\d+)-", os.path.basename(path)).group(1))
lines = open(path, encoding="utf-8").read().split("\n")
if "## Exercises" not in lines:
fail("%s: no '## Exercises' section" % path)
continue
found = re.findall(r"^\*\*(\d+)\.(\d+) ", "\n".join(lines), re.M)
if not found:
fail("%s: Exercises section has no numbered exercises" % path)
for ch, n in found:
if int(ch) != num:
fail("%s: exercise %s.%s is misnumbered (chapter %d)" % (path, ch, n, num))
nums = [int(n) for _, n in found]
if nums != list(range(1, len(nums) + 1)):
fail("%s: exercises are not numbered 1..%d in order" % (path, len(nums)))
total += len(found)

depth, in_code = 0, False
for i, ln in enumerate(lines):
if ln.lstrip().startswith("```"):
in_code = not in_code
if in_code:
continue
s = ln.strip()
if s == "<details>":
depth += 1
if depth > 1:
fail("%s:%d nested <details>" % (path, i + 1))
elif s == "</details>":
depth -= 1
if depth < 0:
fail("%s:%d </details> without <details>" % (path, i + 1))
if i > 0 and lines[i - 1].strip():
fail("%s:%d needs a blank line before </details>" % (path, i + 1))
elif s.startswith("<summary>"):
if i + 1 < len(lines) and lines[i + 1].strip():
fail("%s:%d needs a blank line after <summary>" % (path, i + 1))
if depth != 0:
fail("%s: unbalanced <details> blocks" % path)
print(" %d exercises in %d chapters checked" % (total, len(chapters)))


if __name__ == "__main__":
print("Checking book integrity...")
check_python_blocks()
check_summary_links()
check_headings()
check_internal_links()
check_svgs()
check_exercises()

if errors:
print("\n%d problem(s) found:\n" % len(errors))
Expand Down
59 changes: 59 additions & 0 deletions src/images/bst-successor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions src/images/btree-borrow-merge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions src/images/dijkstra-trace.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading