Directed Graph — Data Structures

🔹 What Is a Directed Graph?

A directed graph is made up of:

  • Nodes (also called vertices) → These are like places, stations, or points.
  • Directed edges (also called arcs) → These are like one-way roads connecting the places.

A directed edge has a start point and an end point.
So it tells you which direction you’re allowed to move.


🎯 Why Do We Need Direction?

Some relationships are not equal.
For example:

  • You can follow someone on Instagram, but they may not follow you back.
  • You can send a message to your teacher, but your teacher might not message you first.
  • In a company, work flows from a manager → team leader → employee, not the other way around.

Whenever a relationship has a clear direction, a directed graph is a perfect way to model it.


📘 Simple Diagram of a Directed Graph

Here’s a small diagram you can easily visualize:

   (A) ---> (B) ---> (C)
     \                ^
      \               |
       -----> (D) ----

What this diagram shows:

  • There is a one-way connection from A to B.
  • There is a one-way connection from B to C.
  • A also connects to D.
  • D connects back to C.

You can think of the arrows like traffic signs saying
You can go this way but not the opposite way.


🌱 Let’s Understand Through a Real-Life Example

📬 Email Flow

When you send an email:

  • You → Your friend (one direction)
  • Your friend may reply, but that is a separate direction.

So the email network forms directed edges from sender to receiver.

🎓 Classroom Example

Suppose you have a chain of command:

  • Principal → Teacher → Class Monitor → Students

Again, each connection is one-way. That’s a directed graph.


🧠 Key Terms (Explained Simply)

1. Out-degree

How many arrows are leaving a node.
Example: If A has arrows going to B and D,
out-degree of A = 2.

2. In-degree

How many arrows are coming into a node.
Example: If C has arrows coming from B and D,
in-degree of C = 2.

3. Path (Directed Path)

A trail you follow by walking along the arrows.
Example: A → B → C is a directed path.

4. Cycle

A loop where you start at one node and come back to it by following directions.
Example: A → D → C → A forms a cycle if arrows allow it.

5. Directed Acyclic Graph (DAG)

A directed graph with no cycles.
Think of it like water flowing downhill — it never loops back.


🛠️ Where Are Directed Graphs Used?

You might be surprised — they’re everywhere!

  • Google Maps (one-way streets)
  • Social media following systems
  • Course prerequisite chains
    (You must complete Course A → before B)
  • Task scheduling
  • Workflow diagrams
  • Computer networks (data routing)

Whenever something moves from point A to point B with direction, a directed graph is quietly working behind the scenes.