GRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No

Similar documents
UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

國立清華大學電機工程學系. Outline

Elementary Graph Algorithms CSE 6331

Konigsberg Bridge Problem

Undirected Graphs. Hwansoo Han

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

Outline. Introduction. Representations of Graphs Graph Traversals. Applications. Definitions and Basic Terminologies


Algorithm Design (8) Graph Algorithms 1/2

Graph Algorithms Using Depth First Search

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Chapter 9 Graph Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Graph. Vertex. edge. Directed Graph. Undirected Graph

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Search means finding a path or traversal between a start node and one of a set of goal nodes. Search is a study of states and their transitions.

Graph and Digraph Glossary

Outline. Graphs. Divide and Conquer.

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

MAT 7003 : Mathematical Foundations. (for Software Engineering) J Paul Gibson, A207.

Index. stack-based, 400 A* algorithm, 325

Lecture 3: Graphs and flows

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

Info 2950, Lecture 16

Graphs: basic concepts and algorithms

Foundations of Discrete Mathematics

Minimum Spanning Trees Ch 23 Traversing graphs

CSC Intro to Intelligent Robotics, Spring Graphs

CS302 - Data Structures using C++

Unweighted Graphs & Algorithms

Graph Theory CS/Math231 Discrete Mathematics Spring2015

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Reference Sheet for CO142.2 Discrete Mathematics II

DESIGN AND ANALYSIS OF ALGORITHMS

Algorithms Sequential and Parallel: A Unified Approach; R. Miller and L. Boxer 3rd Graph Algorithms

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

CS4800: Algorithms & Data Jonathan Ullman

Graph Algorithms (part 3 of CSC 282),

Module 5 Graph Algorithms

Graph traversal is a generalization of tree traversal except we have to keep track of the visited vertices.

CS521 \ Notes for the Final Exam

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Algorithms: Lecture 10. Chalmers University of Technology

Lecture 9 Graph Traversal

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Graph Algorithms. Definition

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Data Structures and Algorithms. Chapter 7. Graphs

Graph Search Methods. Graph Search Methods

Graph Algorithms. Textbook reading. Chapter 3 Chapter 4. CSci 3110 Graph Algorithms 1/41

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Searching in Graphs (cut points)

ROOT A node which doesn t have a parent. In the above tree. The Root is A. LEAF A node which doesn t have children is called leaf or Terminal node.

22 Elementary Graph Algorithms. There are two standard ways to represent a

Chapter 6. GRAPHS. Figure 6.1 : The bridges of Koenigsberg

Math 776 Graph Theory Lecture Note 1 Basic concepts

Copyright 2000, Kevin Wayne 1

W4231: Analysis of Algorithms

Graph Theory. Part of Texas Counties.

Applications of BDF and DFS

Basic Graph Definitions

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Graph Representation

COMP 251 Winter 2017 Online quizzes with answers

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

( ) n 3. n 2 ( ) D. Ο

Lecture 6 Basic Graph Algorithms

Graph: representation and traversal

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Trees Algorhyme by Radia Perlman

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Problem Score Maximum MC 34 (25/17) = 50 Total 100

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

GRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms?

Directed Graphs (II) Hwansoo Han

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Brute Force: Selection Sort

Homework Assignment #3 Graph

Discrete mathematics II. - Graphs

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Data Structure. IBPS SO (IT- Officer) Exam 2017

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

CS 310 Advanced Data Structures and Algorithms

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

Introduction to Optimization

Graphs and Genetics. Outline. Computational Biology IST. Ana Teresa Freitas 2015/2016. Slides source: AED (MEEC/IST); Jones and Pevzner (book)

Graphs & Digraphs Tuesday, November 06, 2007

Transcription:

GRAPHICAL ALGORITHMS UNIT _II Lecture-12 Slides No. 3-7 Lecture-13-16 Slides No. 8-26 Lecture-17-19 Slides No. 27-42

Topics Covered Graphs & Trees ( Some Basic Terminologies) Spanning Trees (BFS & DFS) Disjoint set Operations: Union & Find Algorithms Connected Components Bi-Conncted Components

Graphs The diagrammatical representation of a set of Vertices (nodes) and a set of Edges is called a Graph. It is a non-linear data structure. It is hierarchical structure. Examples: In the real world are Airlines, Source-Destination Network, Konigsberg s Bridges, and Flowchart of a Program.

Graph Terminology 1. Graph 1. Digraph 2. Weighted Graph 2. Adjacent Vertices 3. Self-loop 3. Parallel Edges 4. Simple Graph 4. Complete Graph 5. Circuit 5. Bipartite Graph 6. Isolated Vertex 6. Degree of Vertex 7. Pendant Vertex 7. Connected Graph 8. Path 8. Tree 9. Sub graph 9. Spanning Tree 10.Isomorphic graphs 10. Biconnected Graphs Height, Level, Parent, Child, Ancestor, leaf etc.

A graph is said to be a tree if it is a simple connected graph with no cycles. Directed tree and Non directed tree. In a directed tree there is a specially designated node called the root, remaining nodes are partitioned into n (n>0) disjoint sets T 1, T 2, T 3,,T n, where each T i (i=1,2,3 n) is a tree, T 1, T 2, T 3,,T n are called sub-trees of the root. the path is always fro root to the leaf.

Trees A tree is a non-linear data structure. It require two-dimensional representations. Jan Feb Mar Apr Jul May Aug Jun Oct Nov Dec Sep

A T1 T2 T3 B C D E F G H I J K Fig A Sample Tree T

Representation of Graphs Graph can be represented in many ways: 1. Set representation 2. Linked representation 3. Adjacency Matrix representation 4. Incidence Matrix representation 5. Sparse Matrix representation 6. Multi-lists representation

1. Subgraph 1. A subgraph of a graph G is a graph H whose vertices and edges are subsets of the vertices and edges of G. 2. Spanning Subgraph 1. A Spanning Subgraph of G is subgraph of G that contains all the vertices of the graph G. 3. Forest 1. A Forest is a graph without cycles. 4. Tree 1. A Tree is a connected forest, i.e, a connected graph without cycles. 5. Spanning Tree 1. A Spanning tree of a graph is a spanning subgraph that is a tree.

Graph Traversal Techniques A traversal is a systematic procedure for exploring a graph by examining all of its vertices and edges. A traversal is efficient if it visits all the vertices and edges in time proportional to their number, i.e., in linear time. There are two methods, called Breadth First Search (BFS) and Depth First Search (DFS).

Breadth First Search BFS proceeds in rounds and subdivides the vertices into Levels. BFS can also be thought of as a traversal using a string and paint. With BFS unrolling the string in a more conservative manner. BFS starts at a given vertex s, which is at level-0 and defines the anchor for our string.

BFS Algorithm Input: A connected graph G with vertices labeled V 1, V 2,, V n Output: A Spanning tree T for G. Method: Step1: (Start) Let V 1, be the root of T. From the set V= {V 1 }.

Step2: (Add new edges) Consider the vertices of V in order consistent with the original labeling. Then for each vertex x V, add the edge {x,v k } to T where k is the minimum index such that adding the edge {x, V k }to T does not produce a cycle. If no edge can be added, then stop; T is a spanning tree for G. After all the vertices of v have been considered in order, go to Step 3.

Step3: (Update V) Replace V by all the children Vin T of the vertices x of V where the edges {x, V k } were added in Step2. Go back and repeat Step2 for the new set V.

Algorithm BFT (G, n) { //breadth first traversal graph for i=1 to n do //mark all vertices unvisited visited[i]=0; for i=1 to n do if (visited[i] = 0) then BFS(i); }

Algorithm BFS (v) // code for Breadth First Search { u = v; //q is a queue of unexplored vertices visited[v] = 1; repeat { for all vertices w adjacent from u do { if (visited[w] = 0) then { add w to q; // w is unexplored visited[w] = 1; } } } If q is empty then return; //no unexplored vertex delete u from q; //get unexplored vertex } until(false)

Properties of BFS 1. It is a graph traversal Technique. 2. It is based on visiting FIFO rule. 3. It is based exploring edges. 4. The traversal visits all the vertices in the connected component of s. 5. The discovery edges form a spanning tree T of the connected component of s. 6. For each vertex v at level i, the path of tree T, between s and v has i edges, and any other path of G between s and v has at least i edges. 7. If (u, v) is a cross edge, then the level numbers of u and v differ by at most 1.

2. Let G be a graph with n vertices and e edges represented with the adjacency list structure. 3. The time complexity is O (e + n). 4. Problems can be solved based on BFS are 1. Testing whether G is connected. 2. Computing a spanning forest of G. 3. Computing the connected component of G. 4. Computing a cycle in G, or reporting that G has no cycles. 5. Given a start vertex s of G, computing, for every vertex v of G, path with the minimum number of edges between u an v, or reporting that no such path exists.

DFS DFS is an Non-directed graph. DFS is useful for performing a number of computations on graphs. It also calculates the path from one vertex to another. It determines a graph is connected or not. And computing a spanning tree for a connected graph. It applies Backtracking technique.

DFS Algorithm Input: A connected graph G with vertices labeled V 1, V 2,, V n Output: A Spanning tree T for G. Method: Step1: (Start) Let V 1, be the root of T. And set L=V 1. L stands for the vertex last visited.

Step2: (Find unexamined edge and unvisited vertex adjacent to L) For all vertices adjacent to L, choose the edge {L, V k }, where k is the minimum index such that adding {L, V k } to T does not create a cycle. I f no such edge exists, go to Step 3, otherwise, add edge {L, V k } to T and set L= V k ; repeat Step 2 at the new value for L.

Step3: (Backtrack or terminate) If x is the parent of L in T, set L= x and apply Step2 at the new value of L. If, on the other hand L has no parent in T (so that L=V 1 ) then the depth First Search terminates and T is a spanning tree for G.

Construct Spanning tree using BFS and DFS.

Algorithm DFS(v) { visited[v] = 1; for each vertex w adjacent from v do { if (visited[w] = 0) then DFS(w); } }

Backtracking Algorithm genbacktrack(n) { k = 1; while (k 0) do { if (there remains an untried x[k] T(x[1], x[2],, x[k-1] and B k (x[1], x[2], x[k]) is true) then { if(x[1], x[k] is a path to an answer node) then write (x[1..k]); } else k=k-1; //backtrack to the previous set } }

Algorithm recurbacktrack(k) { for (each x[k] T(x[1], x[2],,x[k-1]) do { if (Bk (x[1], x[2],,x[k]) 0) then { if (x[1], x[2],, x[k]) is a path to an answer node then write (x[1..k]); if (k < n) then backtrack(k+1); } } }

Applications of Graphs 1. Transportation problem 2. Map Coloring 3. Shortest Path Problem 1. Warshall s algorithm 2. Floyd s algorithm 3. Dijkstra s algorithm 4. Topological Sorting algorithm 5. Minimum Spanning Tree 1. Kruskal s algorithm 2. Prim s algorithm 6. Connectivity in Graph 1. Strongly connectivity 2. Bi-connectivity 7. Euler s path and Hamiltonian Circuits 8. Binary Decision Diagram

Let us suppose that we have some finite Universe of n elements, out of which sets will be constructed. These sets may be empty or contain any subsets of the elements of Universe. A common way to represent such sets is to allocate a bit vector of length n, SET(1:n). For example, SET(i) = 1 if the i th element of U is in this set = 0 otherwise.

Let us assume that the elements of the sets are the numbers 1,2,3, n. These numbers are the indices into a symbol table where actual names of elements are stored. Assume that the sets are represented pair wise disjoint. Example: S 1 = {1, 7, 8, 9}; S 2 = {2,5,10}; S 3 = {3,4,6}.

Operations on Disjoint Sets 1. Disjoint set Union: Combining the sets S i U S j = { All elements x such that x is in Si or Sj}. 2. Find(i): Finding the set containing element i.

Simple Union and Find Algorithm Let i and j be the roots of two disjoint sets. Algorithm to Union of two disjoint sets Integer i, j Parent(i) j end of U Algorithm to Find the i th root of the tree containing element i Integer i, j j i While Parent(j)>0 do j Parent(j) repeat return(j) end F

Count(i) = number of nodes in that tree. The count can be maintained in the Parent field as a negative number. Parent(i) = -count(i) If Parent (i)= 0 if this is a root node. Weighting rule for Union (I,j). If the number of nodes in tree I is less than the number in tree j, then make j the parent of I, other wise make I the parent of j.

Weighting Rule for UNION Weighting rule for Union (i, j): If the number of nodes in tree i is less than the number in tree j, then make j the parent of i, other wise make i the parent of j.

UNION Algorithm integer i, j, x x Parent(i) + Parent(j) If Parent(i) > Parent(j) then Parent(i) j Parent (j) x else Parent of (j) i Parent (i) x End if.

Find Algorithm j I While Parent(j) > 0 do j parent(j) Repeat k I While k j do t parent(k) Parent(k) j k t Repeat Return(j) End Find. Note: Using the collapsing rule to collapse all nodes from I to the root j.

Example on Union operation

Let T be a tree with n nodes created as aresult of algorithm Union. No node in T has level greater Floor(logn)+1

A vertex v in a connected graph G is an articulation point iff the deletion of vertex v together with all edges incident to v disconnects the graph into two or more non empty components.

Example

A graph G is bi-connected if and only if it contains no articulation point. G is a maximal bi-connected sub-graph of G if and only if G has no bi connected sub-graph G such that V and E are subsets of V and E

Construction of Bi-Connected Graph Step-1: for each articulation point a do Step-2: let B 1, B 2, B k be the bi-connected components containing vertex a Step-3: let vi, vi a be a vertex in B i, 1 i k Step-4: add to G the edges (v i, v i+1 ) 1 i < k Step-5: repeat Note: The step4 is repeated a is no longer an articulation point.

Finding DFN and L Procedure ART(u,v) Global DFN(n), L(n), num, n DFN(u) num; L(u) num; num num+1 for each vertex w adjacent from u do if DFN(w) = 0 then call ART(w,u) L(u) min(l(u), L(w)) else if w v then L(u) min (L(u), DFN(w)) End if Repeat end ART End if