CS 206 Introduction to Computer Science II

Similar documents
CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II

Module 11: Additional Topics Graph Theory and Applications

Introduction to Graphs. CS2110, Spring 2011 Cornell University

Breadth First Search. Graph Traversal. CSE 2011 Winter Application examples. Two common graph traversal algorithms

Breadth First Search. cse2011 section 13.3 of textbook

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


Graphs and Algorithms

CS302 - Data Structures using C++

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

Graph Search Methods. Graph Search Methods

CSE 100: GRAPH ALGORITHMS

Algorithms: Lecture 10. Chalmers University of Technology

Graph Search Methods. Graph Search Methods

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

CS 206 Introduction to Computer Science II

Graph. Vertex. edge. Directed Graph. Undirected Graph

Algorithm Design and Analysis

Graphs & Digraphs Tuesday, November 06, 2007

Homework Assignment #3 Graph

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes

Outlines: Graphs Part-2

Graphs Chapter 24. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

GRAPHS Lecture 17 CS2110 Spring 2014

An undirected graph G can be represented by G = (V, E), where

CS 206 Introduction to Computer Science II

Graphs. Data Structures 1 Graphs

Graphs: Graph Data Structure:

Understand graph terminology Implement graphs using

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

Algorithm Design and Analysis

CSE 332: Data Abstractions Lecture 15: Topological Sort / Graph Traversals. Ruth Anderson Winter 2013

CSE 100: GRAPH SEARCH

CS 206 Introduction to Computer Science II

Announcements Problem Set 4 is out!

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.

CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT

CS 206 Introduction to Computer Science II

CSE 373: Data Structures and Algorithms

Some major graph problems

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

CS1114 Assignment 3. 1 Previously, on Assignment 2. 2 Linked lists

CS4800: Algorithms & Data Jonathan Ullman

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Basic Graph Definitions

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

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

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

GRAPHS Lecture 19 CS2110 Spring 2013

Worksheet for the Final Exam - Part I. Graphs

(Re)Introduction to Graphs and Some Algorithms

CS 310 Advanced Data Structures and Algorithms

CS 206 Introduction to Computer Science II

12 Abstract Data Types

Chapter 9. Priority Queue

CSC263 Week 8. Larry Zhang.

Inf 2B: Graphs, BFS, DFS

Trees. Arash Rafiey. 20 October, 2015

LECTURE 17 GRAPH TRAVERSALS

I A graph is a mathematical structure consisting of a set of. I Formally: G =(V, E), where V is a set and E V V.

Mystery Algorithm! ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v )

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees. Lecture 22 CS2110 Spring 2017

CS2 Algorithms and Data Structures Note 9

CSC Intro to Intelligent Robotics, Spring Graphs

22.1 Representations of graphs

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico

Graphs Introduction and Depth first algorithm

CS Algorithms and Complexity

CS 491 CAP Introduction to Graphs and Search

Topic 12: Elementary Graph Algorithms

Undirected Graphs. Hwansoo Han

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship

Algorithm Design and Analysis

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

18: GRAPH DATA STRUCTURES. Introduction

CS4800: Algorithms & Data Jonathan Ullman

W4231: Analysis of Algorithms

Graphs: A graph is a data structure that has two types of elements, vertices and edges.

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

COMP 182 Algorithmic Thinking. Breadth-first Search. Luay Nakhleh Computer Science Rice University

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Algorithms and Data Structures, Academic Year 2010/2011

Do you remember what is the most powerful tool for managing complexity?

3.1 Basic Definitions and Applications

Implementing Algorithms

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

CS 2412 Data Structures. Chapter 9 Graphs

Graphs and Graph Algorithms. Slides by Larry Ruzzo

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

Unweighted Graphs & Algorithms

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

CS61BL. Lecture 5: Graphs Sorting

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph:

Lecture 9 Graph Traversal

Introduction to Graphs. common/notes/ppt/

Transcription:

CS 206 Introduction to Computer Science II 04 / 06 / 2018 Instructor: Michael Eckmann

Today s Topics Questions? Comments? Graphs Definition Terminology two ways to represent edges in implementation traversals Michael Eckmann - Skidmore College - CS 206 - Spring 2018

Graphs consist of a set of vertices and a set of edges. An edge connects two vertices. Edges can be directed or undirected. Directed graphs' edges are all directed. Undirected graphs' edges are all undirected. Directed graphs are sometimes called digraphs. Two vertices are adjacent if an edge connects them. The degree of a vertex is the number of edges starting at the vertex. Two vertices v1 and v2 are on a path if there are a list of vertices starting at v1 and ending at v2 where each consecutive pair of vertices is adjacent.

The length of a path is the number of edges in the path. A simple path is one whose edges are all unique. A cycle is a simple path, starting and ending at the same vertex. A vertex is reachable from another vertex if there is a path between them. A graph is connected if all pairs of vertices in the graph have a path between them. Example on the board of a connected and an unconnected graph. A complete graph (aka fully connected graph) is a connected graph where all pairs of vertices in the graph are adjacent. Example on the board.

Connectivity of a digraph A digraph is strongly connected if there is a path from any vertex to any other vertex (following the directions of the edges) A digraph is weakly connected if in its underlying undirected graph, there is a path from any vertex to any other vertex Degree of a vertex in a digraph In-degree of a vertex is the number of edges entering the vertex Out-degree of a vertex is the number of edges leaving the vertex

Edges often have a weight associated with them. An edge's weight is some numeric value. Can someone define a tree (assuming the nodes are vertices and the edges are undirected) in graph terms?

Edges often have a weight associated with them. An edge's weight is some numeric value. Can someone define a tree (assuming the nodes are vertices and the edges are undirected) in graph terms? Trees are connected graphs without cycles.

Examples of using graphs to represent real world problems A weighted graph that connect cities (vertices) and the weights of the edges might be length of time to travel between the two cities. A graph whose vertices represent buildings on campus and edges are sidewalks connecting the buildings. History of computer programming languages (directed edge from a language that influenced a later language) Is it possible that this is a tree? why/why not?

Graphs can be represented in programs in many ways. Two common ways to represent them are: adjacency matrix --- each row number r represents a vertex and the value at column c is true if there's an edge from vertex r to vertex c, false otherwise Notice that the type stored in the adjacency matrix is boolean Could we use this for weighted graphs? Could we use this for directed graphs? edge lists store a linked list for each vertex, v i items in the list are those vertices v j for which there's an edge from v i to v j

Graph traversals what are traversals? --- we used that word when we worked on binary trees

Graph traversals Breadth First Search (BFS) and Depth First Search (DFS) are traversals

Graph traversal Breadth first search (BFS) Pick a vertex at which to start Visit all of the adjacent vertices to the start vertex Then for each of the adjacent vertices, visit their adjacent vertices And so on until there are no more adjacent vertices Do not visit a vertex more than once Only vertices that are reachable from the start vertex will be visited --- example on the board. The order that vertices in a BFS are visited are in increasing order of length of path from starting vertex. Those that have the same path length from the start vertex can be visited in any order. Example of BFS on the board.

Implementation of breadth first search Need a flag for each vertex to mark it as unvisited, waiting, or visited so we don't visit vertices more than once. Keep a queue which will hold the vertices to be visited Keep a list of vertices as they are visited BFS algorithm: Mark all vertices as unvisited Initially enqueue a vertex into the queue, mark it as waiting While the queue is not empty Dequeue a vertex from the queue Put it in the visited list, mark it as visited Enqueue all the adjacent vertices that are marked as unvisited to the vertex just dequeued. Mark the vertices just enqueued as waiting

Let's see how far we get with implementation of a graph with edge list representation of edges and breadth first search. You will, in a programming assignment, implement graphs with adjacency matrix representation of edges.