


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive introduction to graph theory, a fundamental concept in computer science. It covers key definitions, terminology, and examples related to graphs, including vertices, edges, adjacency, degree, paths, cycles, subgraphs, and connected components. The document also explores different graph representations, such as adjacency matrices and adjacency lists, and discusses their advantages and disadvantages. Additionally, it delves into graph traversal algorithms, including depth-first search (dfs) and breadth-first search (bfs), highlighting their applications in finding paths and exploring graph structures.
Typology: Summaries
1 / 34
This page cannot be seen from the preview
Don't miss anything!
Muhammad Hussain Mughal
What is a Graph? A graph G = (V,E) is composed of: V: set of vertices E: set of edges connecting the vertices in V An edge e = (u,v) is a pair of vertices Example:
V= {a,b,c,d,e} E= {(a,b),(a,c), (a,d), (b,e),(c,d),(c,e), (d,e)}
Terminology: Adjacent and Incident
v 0 and v 1 are adjacent The edge (v 0 , v 1 ) is incident on vertices v 0 and v 1
v 0 is adjacent to v 1 , and v 1 is adjacent from v 0 The edge <v 0 , v 1 > is incident on v 0 and v 1
the in-degree of a vertex v is the number of edges that have v as the head the out-degree of a vertex v is the number of edges that have v as the tail if di is the degree of a vertex i in a graph G with n vertices and e edges, the number of edges is
i n
0 1
Why? Since adjacent vertices each count the adjoining edge, it will be counted twice
Terminology: Path path: sequence of vertices v 1 ,v 2 ,.. .v k such that consecutive vertices v i and v i+ are adjacent. 3 (^3 ) 3 2 a (^) b c d e a (^) b c d e a b e d c b e d c
More Terminology simple path: no repeated vertices cycle: simple path, except that the last vertex is the same as the first vertex a (^) b c d e b e c a c d a a (^) b c d e
(i) (ii) (iii) (^) 3 (iv) (a) Some of the subgraph of G 1 0 0 1
(i) (ii) (iii) (iv) (b) Some of the subgraph of G 3
Subgraphs Examples
More… tree - connected graph without cycles forest - collection of trees tree forest tree tree tree
More Connectivity
If m < n - 1, G is not connected
Oriented (Directed) Graph
ADT for Graph objects: a nonempty set of vertices and a set of undirected edges, where each edge is a pair of vertices functions: for all graph Graph , v , v 1 and v 2 Vertices Graph Create()::=return an empty graph Graph InsertVertex( graph , v )::= return a graph with v inserted. v has no incident edge. Graph InsertEdge( graph , v 1 , v 2 )::= return a graph with new edge between v 1 and v 2 Graph DeleteVertex( graph , v )::= return a graph in which v and all edges incident to it are removed Graph DeleteEdge( graph , v 1 , v 2 )::=return a graph in which the edge ( v 1 , v 2 ) is removed Boolean IsEmpty( graph )::= if ( graph == empty graph ) return TRUE else return FALSE List Adjacent( graph , v )::= return a list of all vertices that are
Graph Representations
0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0
symmetric
Merits of Adjacency Matrix
j n
0 1 ind vi A j i j n ( ) [ , ]
0 1 outd vi A i j j n ( ) [ , ]
0 1