Types of Graph
Types of Graphs
Graphs can vary based on how their edges behave, whether they carry weights, and how their nodes are connected. Understanding graph types is key to choosing the right algorithm for your problem.
1. Undirected Graph
- Edges have no direction.
- If there’s an edge between A and B, you can go from A to B and also from B to A.
- These graphs represent two-way relationships.
Example: A friendship network – if Alice is friends with Bob, Bob is also friends with Alice.
2. Directed Graph
- Edges point in one direction.
- An edge from A to B only allows movement from A to B, not the other way.
- Also called a digraph.
Example: Web links – one page may link to another, but not necessarily the reverse.
3. Weighted Graph
- Each edge has a value (weight) that represents distance, cost, time, etc.
- Used when connections have varying importance or size.
Example: A road map where each road has a distance or travel time.
4. Unweighted Graph
- All edges are treated equally.
- Edges don’t carry additional values—every connection is the same.
Example: A family tree or organizational chart where relationships just "exist" or "don’t".
5. Cyclic Graph
- Contains at least one cycle—a path that starts and ends at the same node.
- The cycle must have at least three distinct nodes (to avoid looping back on a single edge).
Example: A social network loop where you can return to your starting friend by following friend connections.
6. Acyclic Graph
- Contains no cycles—you can’t return to the same node once you've left it.
There are two important cases:
-
Undirected Acyclic Graph
- If it’s also connected, it is called a Tree.
- A group of trees is called a Forest.
-
Directed Acyclic Graph (DAG)
- A graph with directed edges and no cycles.
- Can be topologically sorted, meaning nodes can be arranged linearly to respect the direction of edges.
Example of DAG: Task scheduling – task A must happen before task B.
7. Connected Graph
- Every vertex is reachable from every other vertex.
- Applies to undirected graphs.
Example: A network where all devices are linked directly or indirectly.
8. Disconnected Graph
- At least one node cannot be reached from another.
- The graph is made up of separate connected components.
Example: Two social groups with no connections between them.
9. Strongly Connected Graph
- Applies to directed graphs.
- A graph is strongly connected if there is a path from every node to every other node and back.
Example: In a city road system, if every one-way street still allows you to reach all other streets and return.
| Graph Type | Direction | Weights | Cycles Allowed | Example |
|---|---|---|---|---|
| Undirected | ? | Optional | Yes/No | Friendship network |
| Directed | ? | Optional | Yes/No | Web links |
| Weighted | ? / ? | ? | Yes/No | Road map |
| Unweighted | ? / ? | ? | Yes/No | Family tree |
| Cyclic | ? / ? | Optional | ? | Group of people forming a circle |
| Acyclic (Tree/DAG) | ? / ? | Optional | ? | Task scheduling, directory tree |
| Connected | ? | Optional | Yes/No | Fully linked network |
| Disconnected | ? / ? | Optional | Yes/No | Multiple separate subgraphs |
| Strongly Connected | ? | Optional | Yes/No | Fully reachable city map (one-way) |
🤖 Don't fully get this? Learn it with Claude
Stuck on Types of Graph? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **Types of Graph** (DSA) and want to truly understand it. Explain Types of Graph from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **Types of Graph** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **Types of Graph** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **Types of Graph** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.