Day 18
Day 18: Introduction to Graphs
18/60 Days
Introduction to Graphs#
Welcome to Day 18 of our 60 Days of Coding Algorithm Challenge! Today, we’ll dive into the world of graphs, a versatile and powerful data structure used to represent relationships between entities.
What is a Graph?#
A graph is a non-linear data structure consisting of nodes (or vertices) and edges. The nodes are the entities we want to represent, and the edges are the relationships or connections between these entities.
Formally, a graph G is an ordered pair of a set V of vertices and a set E of edges, written as G = (V, E).
Basic Graph Terminology#
- Vertex (Node): A fundamental unit of which graphs are formed.
- Edge: A connection between two vertices in a graph.
- Adjacent Vertices: Two vertices are said to be adjacent if there’s an edge connecting them.
- Degree of a Vertex: The number of edges connected to a vertex.
- Path: A sequence of vertices where each adjacent pair is connected by an edge.
- Cycle: A path that starts and ends at the same vertex.
Types of Graphs#
- Undirected Graph: Edges have no direction.
- Directed Graph (Digraph): Edges have directions.
- Weighted Graph: Edges have weights or costs associated with them.
- Unweighted Graph: All …
Keep your momentum going
Create a free account to unlock the full lesson, all 60 days, and track your progress as you go.
- Full access to all 60 daily lessons
- Track completion and build a daily streak
- Get interview-ready, one algorithm at a time
Join 2,900+ learners · 4.8/5 average rating