Data Structure Graphs Survival Guide
We have all heard about graphs within the computer science field, and probably just thought about a normal graph only to find out that was completely wrong. Well don’t worry, I am here to help with a quick survival guide.
Nodes
- Nodes are also known as vertices or vertex
- Can also have value
In the example above the nodes are shown as circles with different number values.
Arrows
- Also known as edges.
- Connects the nodes with a direction
Connected/Unconnected
- A graph is connected if all of the nodes are linked in one way or another. Let’s take a look at an example.
In the example above, you can see that Nodes 8 and 9 aren't connected to the rest of the graph.
Cyclic
- Cyclic graph is when you can have an infinite loop between nodes.
- Another way to think about it would be if you follow the direction of the graph and find your way back to a node you’ve already traversed.
In the example above, you can see that we have a cyclic graph. The reason is that between nodes 3,4, and 5 you can see that you can go in the same direction an infinite amount of times.
Acyclic
- A graph that has no cycles.
Directed
- A directed graph is when the arrows or edges are pointed to other nodes
Undirected
- An undirected graph is when the edges aren’t pointing to another node.