Graphs Basic Concepts For more notes and topics visit: www.eITnotes.com eITnotes.com Graphs – Basic Concepts Basic definitions: vertices and edges More definitions: paths, simple paths, cycles, loops Connected and disconnected graphs Complete graphs Weighted graphs Graph representation Adjacency matrix Adjacency lists eITnotes.com Basic Graph Definitions A graph is a non-linear data structure that consists of a collection of nodes(or vertices) and a collection of edges(or arcs), with each edge joining one node to another. Formally, a graph G = (V,E) consists of two sets: a) V called set of all vertices or nodes. b) E called set of all edges or arcs. Vertices are represented by circles or points and edges as line segments or arcs connecting the vertices. eITnotes.com Vertices and Edges Definition: A graph is a collection (nonempty set) of vertices and edges Vertices: can have names Edges: connect two vertices, can be labeled, can be directed Adjacent vertices: there is an edge between eITnotes.com them Graph1 Example Vertices: A,B,C,D Edges: A AB, AC, BC, CD C B A C D Two ways to draw the same graph B D eITnotes.com Graph2 Directed and undirected graphs Graph3 A B A B C C D D These are two different graphs eITnotes.com More definitions : Path A list of vertices in which successive vertices are connected by edges ABC A B BACD ABCABCABCD BABAC C eITnotes.com D More definitions : Simple Path No vertex is repeated. ABCD D CA A B C eITnotes.com DCB AB ABC D More definitions : Cycle A loop is a special case of cycle in which an edge begin and ends with the same vertex. ABCA A B BACB CBAC C D eITnotes.com A graph without cycles is called acyclic graph. Connected and Disconnected graphs Connected graph: There is a path between each two vertices Disconnected graph : There are at least two vertices not connected by a path. Examples of disconnected graphs: A B C D A C B eITnotes.com D Degree of vertex In an undirected graph, the degree of a vertex is the number of edges originating from it. In directed graph degree of vertex comes in two variations: a) Indegree b) Outdegree eITnotes.com Complete graphs Graphs with all edges present – each vertex is connected to all other vertices A B C D E A complete graph eITnotes.com Weighted graphs Weighted graphs – weights are assigned to each edge (e.g. road map) 1 B 2 C 2 A 4 3 D eITnotes.com Graph Representation Adjacency matrix Adjacency lists eITnotes.com Adjacency matrix – undirected Vertices: A,B,C,D graphs Edges: AC, AB, AD, BD The matrix is symmetrical A B C D A 0 1 1 1 B 1 0 0 1 C 1 0 0 1 D 1 1 0 0 A B C D eITnotes.com Adjacency matrix – directed Vertices: A,B,C,D graphs Edges: AC, AB, BD, DA A B C D A 0 1 1 0 B 0 0 0 1 C 0 0 0 0 D 1 0 0 0 A B C D eITnotes.com Adjacency lists – undirected Vertices: A,B,C,D graphs Edges: AC, AB, AD, BD Heads lists A BCD B AD C A D AB A B C D eITnotes.com Vertices: Edges: Adjacency lists – directed graphs A,B,C,D AC, AB, BD, DA A Heads lists A BC B D C = D A B C D eITnotes.com
© Copyright 2026 Paperzz