High Graphs Question 174 of 224

How does Dijkstra find shortest paths from a source on a weighted graph with non-negative edges?

DSA interview set · Speak this in 60–90 seconds · Faridabad & Delhi NCR

PICTURE THIS: DATA SPLIT

Train 70%Val 15%Test 15%

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.

1

WHY — Graphs instead of guessing?

Why interviewers care about Graphs:

This is a process

question about Graphs.

Panels listen for order,

trade-offs, and what you would actually do on a DSA project - not buzzwords.

Stay structured

Name the idea, why it exists, then one short example.

Close cleanly

End with when you use it and one common pitfall.

2

STEPS — What happens with tokens?

Before the model can read a sentence, it goes through these steps:

  1. 1
    A min-heap of (distance,

    node) always settles the closest unsettled vertex and relaxes its edges.

  2. 2
    With a binary heap,

    time is O((V+E) log V) and space is O(V).

  3. 3
    Negative edges break the

    greedy settle step

  4. 4
    Context mix

    then use Bellman-Ford.

  5. 5
    Next token

    The model scores what should come next.

  6. 6
    Decode

    IDs turn back into readable text.

3

EXAMPLE — See it in action

Let's see how a real sentence is tokenized (tokens may vary by model):

Input text
“With a binary heap, time is O((V+E) log V) and space is O(V).”
Tokenized output
Withabinaryheaptimeis
Token IDs (example)
2987408337471632900

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).

Chat with us