View on GitHub

advent-of-code-2024

Readable Advent of Code 2024 algorithms and solutions in C language

Day 16: Reindeer Maze

Let $G=(V,E)$ be a graph.

Let $D$ be the set of directions where for all $d\in D$, we have $d:V\to V$.

Let $R_0:D\to D$ and $R_1:D\to D$ be rotation functions.

Let $s\in V$ be the source vertex, $t\in V$ be the target vertex, and $d^\ast\in D$ be the current direction.

Part A

Algorithm 1:

Algorithm 2 (Dijkstra’s algorithm):

Time complexity: $O((\lvert V\rvert+\lvert E\rvert)\log{\lvert V\rvert})=O(\lvert V\rvert\log{\lvert V\rvert})$ for $\lvert E\rvert=O(\lvert V\rvert)$.

Space complexity: $O(\lvert V\rvert)$.

Part B

Algorithm 3:

Algorithm 4 (Depth-first search) with $u\in V,d\in D,w^*$, and $r_v\in\lbrace\mathrm{true},\mathrm{false}\rbrace$ for all $v\in V$ as arguments:

Time complexity: $O((\lvert V\rvert+\lvert E\rvert)\log{\lvert V\rvert})=O(\lvert V\rvert\log{\lvert V\rvert})$ for $\lvert E\rvert=O(\lvert V\rvert)$.

Space complexity: $O(\lvert V\rvert)$.