This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: B.B. Karki, LSU 1 CSC 3102 Graphs B.B. Karki, LSU 2 CSC 3102 Graph Basics Notion of a graph Main varieties Undirected, directed and weighted graphs Complete, dense and sparse graphs Two principal representations Adjacency matrix Adjacency linked lists Important properties Connectivity Acyclicity Shortest paths Spanning trees B.B. Karki, LSU 3 CSC 3102 Notion of a Graph A graph G = V, E is a pair of two sets: a finite set V of items called vertices (or nodes) and a set E of pairs of these items called edges (or arcs). Undirected graph: a pair of vertices ( u,v ) is the same as the pair ( v,u ). Directed graph or digraphs: the edge ( u,v ) is directed from vertex u to vertex v . Vertices are often labeled with letters and integers. Number of edges  E  possible in an undirected graph with  V  vertices and no loops satisfy the following in equality: A graph with every pair of its vertices connected by an edge is called complete. Few possible edges missing: dense graph. Only few edges existing: sparse graph.  E   V ( V  1)/2 d a e c f b d a e c f b Undirected graph Directed graph B.B. Karki, LSU 4 CSC 3102 Graph Representations Adjacency matrix An nby n boolean matrix with one row and one column for each of the graphs n vertices, in which the element in the i th row and the j th column is equal to 1 if there is an edge from the i th vertex to the j th vertex and equal to if there is no such edge. We use a vector to store vertices and a matrix to store edges. Adjacency linked lists A collection of linked lists, one for each vertex, that contain all the vertices adjacent to the lists vertex (i.e., all the vertices connected to it by an edge). We use a linkedlist to store the vertices and a two dimensional linked list to store edges . If the graph is sparse, the adjacency linked lists represent more spaceefficient than the adjacency matrix. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 a b c d e f a b c d e f a c d b c f c a b e d a e e c d f f b e Adjacency matrix Adjacency linked lists B.B. Karki, LSU 5 CSC 3102 Weighted Graphs A weighted graph is a graph with numbers assigned to its edges. These numbers are called weights or costs. Finding shortest path between two points in a transportation or communication network. In adjacency matrix representation, the element A [ i,j ] will simply contain the weight of the edge from the i th to j th vertex if there is such an edge, and a special symbol, e.g., , if there is no such edge....
View
Full
Document
 Fall '08
 Kraft,D

Click to edit the document details