220 likes | 293 Views
Graph Concepts. Samia Qader Hw # 5 all images obtained from LEDA software in the following directory: 252a/handout/demo/graphwin/graphwin. Nodes, Edges. Graph G = (V,E) where V = (1,2, ..,n)
E N D
Graph Concepts Samia Qader Hw # 5 all images obtained from LEDA software in the following directory: 252a/handout/demo/graphwin/graphwin
Nodes, Edges • Graph G = (V,E) where V = (1,2, ..,n) n= no.of nodes or vertices E= the edge set of G, its elements are called edges • Examples of nodes: 0,1,2,3 • Examples of Edges: between 0,1 and 0,2
Multiple Edges • When there is more than one edge between a set of vertices this is known as a multiple edge. • Example: Multiple edge between nodes 2 and 5
Loops • A loop is an edge leaving from one vertex(node), returning to the same vertex. • Example: loop on node 3
Undirected Graph • An undirected G= (V,E), the edge set E consists of unordered pair of vertices. • Self-loops are forbidden in an undirected graph
Directed Graph (digraph) • A directed graph or digraph G is a pair (V,E) such that the edge set E has an ordered pair of vertices.
Simple Graph • A simple graph has no loops and no multiple edges
Examples of graphs • Graph G = (V,E) where V = (1,2, ..,n) n= no.of nodes or vertices E= the edge set of G, its elements are called edges
Examples of multigraphs • A multigraph is like an undirected graph but it can have both multiple edges between vertices and self-loops
A Complete Graph • A complete graph is an undirected graph in which every pair of vertices is adjacent (i.e. there is an edge between every pair of vertices)
A bipartite graph • In a bipartite graph, the vertices are divided into two classes and all the edges go between these two classes of vertices.
A path in an undirected graph • A path in an undirected graph from vertex a to vertex z is a sequence of vertices (v0,v1,..,vk) s.t. a = v0 and z= vk. • The length of the path is the number of edges in the path • Example: path from 0 to 5 is of length 5.
Path in a directed graph • A path in an undirected graph from vertex a to vertex z is a sequence of vertices (v0,v1,..,vk) s.t. a = v0 and z= vk. • The length of the path is the number of edges in the path • Example: path from 0 to 5 is of length 5.
Hamilton Path Example 1 • Hamilton path in a graph is a path that spans all vertices • Example 1: In a directed graph • Example 2: In an undirected graph Example 2
A cycle in a directed graph • In a directed graph, a path (v0,v1,…,vk) forms a cycle if v0=vk and the path contains at least one edge • In a cycle, each vertex has exactly 2 neighbors and the graph is connected
A cycle in an undirected graph • In an undirected graph, a path (v0, v1, …,vk) forms a cycle if v0 = vk and v0,v1,..,vk are distinct • Example: nodes 0,1,2,3 form a cycle
Hamilton Cycle Example 1 • A Hamilton Cycle is a cycle that covers all the vertices • Example 1: A Hamilton Path in a digraph • Example 2: A Hamilton Path in an undirected graph Example 2
Cyclic and Acyclic Digraphs • A cyclic digraph contains cycles- example 1 • An acyclic digraph has no cycles- example 2 Example 1 Example 2
Tree • A tree is a special class of graphs. It is a connected, acyclic, undirected graph.
Forest • A group of trees that is not connected is called a forest • If an undirected graph is acyclic but possibly disconnected, it is a forest
Graph which is not connected Example 1 • An undirected graph is not connected if every pair of vertices is not connected by a path. • Example1: This graph is not connected because vertex 2 is not connected by a path.
Graph which is not connected Example 2 • Example 2: This graph is not connected since vertices 2 and 8 are not connected by a path.