Graph Theory - I. Today’s Plan Introduction Special Graphs Various Representations Depth First Search Solve a problem from GCJ Breadth First Search Solve.

Slides:



Advertisements
Similar presentations
Review Binary Search Trees Operations on Binary Search Tree
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
Graph Theory, DFS & BFS Kelly Choi What is a graph? A set of vertices and edges –Directed/Undirected –Weighted/Unweighted –Cyclic/Acyclic.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
1 Dijkstra’s Minimum-Path Algorithm Minimum Spanning Tree CSE Lectures 20 – Intro to Graphs.
Graph Searching CSE 373 Data Structures Lecture 20.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 27 Graphs and Applications.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Graphs-Part II Depth First Search (DFS). We Already Covered Breadth First Search(BFS) Traverses the graph one level at a time – Visit all outgoing edges.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Search Related Algorithms. Graph Code Adjacency List Representation:
CS200 Algorithms and Data StructuresColorado State University Part 10. Graphs CS 200 Algorithms and Data Structures 1.
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
Graph Introduction, Searching Graph Theory Basics - Anil Kishore.
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Topic 12 Graphs 1. Graphs Definition: Two types:
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs & Paths Presentation : Part II. Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Graphs Chapter 20.
Graphs Representation, BFS, DFS
Introduction to Graphs
Unweighted Shortest Path Neil Tang 3/11/2010
CS120 Graphs.
Short paths and spanning trees
Graphs Graph transversals.
Graphs Representation, BFS, DFS
Chapter 22: Elementary Graph Algorithms I
Graph Representation (23.1/22.1)
Chapter 11 Graphs.
ITEC 2620M Introduction to Data Structures
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 16 1 – Graphs Graph Categories Strong Components
CSE 417: Algorithms and Computational Complexity
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Lecture 10 Graph Algorithms
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Graph Theory - I

Today’s Plan Introduction Special Graphs Various Representations Depth First Search Solve a problem from GCJ Breadth First Search Solve a problem from SPOJ Dijkstra’s Algorithm Solve a problem from SPOJ

Special Graphs Undirected Graphs Edge Weighted Graphs Directed Graphs Trees Directed Acyclic Graphs Bi-Partite Graphs

Representation - I Adjacency matrix 2 D Array M of size |V|x|V| M[i][j] – 1 if Vi and Vj are connected by and edge and 0 otherwise. Adjacency List Each vertex maintains a list of vertices that are adjacent to it. We can use: vector >

Representation - II Edge List Checking if edge (Vi,Vj) is present in G. Adjacency Matrix – O(1) Adjacency List – O(min(deg(Vi),deg(Vj))) Iterating through the list of neighbours of Vi Adjacency Matrix – O(|V|) Adjacency List – O(deg(Vi))

Representation - III Implicit graphs Two squares on an 8x8 chessboard. Determine the shortest sequence of knight moves from one square to the other. Tricks: Use Dx[], Dy[] for generating the neighbors of a position in grid problems.

Depth First Search Finding Connected Components Implemented using Stack Recursion (Most Frequently used) Complexity Time: O(|V|+|E|) Space: O(|V|) [to maintain the vertices visited till now] Google Code Jam Problem 1#s=p1 1#s=p1

Breadth First Search Finding a Path with Minimum # of edges from starting vertex to any other vertex. Used to Solve Shortest Path problem in un weighted graphs Implemented using queue Same Time and Space Complexity as DFS. SPOJ Problem

Dijkstra’s Algorithm Used to solve Shortest Path problem in Weighted Graphs Only for Graphs with positive edge weights Greedy strategy Use priority_queue for implementing Dijkstra’s SPOJ Problem

Practice problems

More Practice Problems SRM Division Pt