Data Structure - Unit IV - Graph
Graph – IV Definition of Graph A graph is a non-linear data structure consisting of a set of vertices (nodes) and a set of edges (links) that connect pairs of vertices. Standard Definition: A graph is defined as G = (V, E) where: V = set of vertices E = set of edges Simple Explanation: Vertices = points (like A, B, C) Edges = connections between them Example: If V = {A, B, C} E = {(A, B), (B, C)} Then the graph connects: A — B — C Graph Representation in Data Structure Graphs can be represented in a computer mainly in two ways : 1. Adjacency Matrix A graph is represented using a 2D array (matrix) Idea: · Rows and columns represent vertices · Value = 1 (or weight) if edge exists, otherwise 0 Example: Graph: A — B, A — C, B — C Matrix: ...