How does Dijkstra find shortest paths from a source on a weighted graph with non-negative edges?
PICTURE THIS: DATA SPLIT
Fit on train, tune on val, report on test once.
Simple meaning
A min-heap of (distance, node) always settles the closest unsettled vertex and relaxes its edges.
WHY — Graphs instead of guessing?
Why interviewers care about Graphs:
question about Graphs.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens with tokens?
Before the model can read a sentence, it goes through these steps:
- 1A min-heap of (distance,
node) always settles the closest unsettled vertex and relaxes its edges.
- 2With a binary heap,
time is O((V+E) log V) and space is O(V).
- 3Negative edges break the
greedy settle step
- 4Context mix
then use Bellman-Ford.
- 5Next token
The model scores what should come next.
- 6Decode
IDs turn back into readable text.
EXAMPLE — See it in action
Let's see how a real sentence is tokenized (tokens may vary by model):
Note: Actual tokens and IDs depend on the tokenizer (e.g., GPT, Llama, etc.).
Key takeaway
A min-heap of (distance, node) always settles the closest unsettled vertex and relaxes its edges. With a binary heap, time is O((V+E) log V) and space is O(V).