What is a graph in computer science?
Options
- A chart with axes, used to plot data
- A set of nodes (vertices) connected by edges (Correct option)
- A sorted list of values with links
- A type of loop that repeats over nodes
Answer
A set of nodes (vertices) connected by edges
Why
A graph models things and connections between them: cities and roads, users and friendships, web pages and links.
Edges can be directed (one-way, like following someone) or undirected (two-way), and weighted (with a cost, like distance) or not.
A tree is a special graph with no cycles.
Remember
Graph = nodes + edges.