CS171 Introduction to Computer Science II Graphs Strike Back.

Slides:



Advertisements
Similar presentations
Problem solving with graph search
Advertisements

The A* Algorithm Héctor Muñoz-Avila. The Search Problem Starting from a node n find the shortest path to a goal node g ?
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Solving Problem by Searching
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Part A - Terminology and Traversals
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
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.
PSU CS Algorithms Analysis and Design Graphs.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graph Searching CSE 373 Data Structures Lecture 20.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Breadth-First and Depth-First Search
Chapter 8, Part I Graph Algorithms.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graph & BFS.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
Graphs.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Social Media Mining Graph Essentials.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
COSC 2007 Data Structures II Chapter 14 Graphs III.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
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.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
For Monday Read chapter 4, section 1 No homework..
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.
Search exploring the consequences of possible actions.
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Informed Search Reading: Chapter 4.5 HW #1 out today, due Sept 26th.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graph Algorithms GAM 376 Robin Burke Fall Outline Graphs Theory Data structures Graph search Algorithms DFS BFS Project #1 Soccer Break Lab.
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 Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
Search Techniques CS480/580 Fall Introduction Trees: – Root, parent, child, sibling, leaf node, node, edge – Single path from root to any node Graphs:
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Chapter 05 Introduction to Graph And Search Algorithms.
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.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
The A* Algorithm Héctor Muñoz-Avila.
Graphs Chapter 11 Objectives Upon completion you will be able to:
CSE 373: Data Structures and 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 .
Presentation transcript:

CS171 Introduction to Computer Science II Graphs Strike Back

Homework 5! Emory Movie Database (EMD) Due Wednesday 4/7 11:59pm!

Depth-First Search (DFS) – Non-recursive algorithm Push s onto a stack Repeat until the stack is empty: – remove the top vertex v. if not visited, mark as visited – add all v’s unvisited neighbors to the stack

DFS in real-life (xkcd)

Graphs Definitions Implementation/Representation of graphs Undirected graphs – Algorithms Depth-first search Breadth-first search Path finding and shortest path Connected components – Applications

BFS example

Graphs Definitions Implementation/Representation of graphs Undirected graphs – Algorithms Depth-first search Breadth-first search Path finding and shortest path Connected components – Applications

Graphs Definitions Implementation/Representation of graphs Undirected graphs – Algorithms Depth-first search Breadth-first search Path finding and shortest path Connected components – Applications

Six degrees of separation Everyone is on average approximately six steps away, by way of introduction, from any other person on Earth Online social networks – Facebook: average distance is 4.74 (Nov 2011) – Twitter: average distance is 4.67 Erdos number Bacon number

Application: Web Search Engines i.Gather the contents of all web pages (using a program called a crawler or spider) ii.Organize the contents of the pages in a way that allows efficient retrieval (indexing) iii. Take in a query, determine which pages match, and show the results (ranking and display of results) A Search Engine does three main things:

Basic structure of a search engine: Crawler disks Index indexing hooli.com Query: “computer” look up

Breadth-First Crawl: Basic idea: - start at a set of known URLs - explore in “concentric circles” around these URLs start pages distance-one pages distance-two pages

Graphs Definitions Implementation and representation of graphs Simple graphs – Depth-first search – Breadth-first search – shortest path – Connected components Directed graphs Weighted graphs Shortest path Minimum Spanning Tree

Edge-weighted graphs Each connection has an associated weight

Graphs Simple graphs Algorithms – Depth-first search – Breadth-first search – shortest path – Connected components Directed graphs Weighted graphs Shortest path Minimum Spanning Tree

Dijkstra’s Algorithm Finds all shortest paths given a source Solves single-source, single- destination, single-pair shortest path problem Intuition: grows the paths from the source node using a greedy approach

Shortest Paths – Dijkstra’s Algorithm Assign to every node a distance value: set it to zero for source node and to infinity for all other nodes. Mark all nodes as unvisited. Set source node as current. For current node, consider all its unvisited neighbors and calculate their tentative distance. If this distance is less than the previously recorded distance, overwrite the distance (edge relaxation). Mark it as visited. Set the unvisited node with the smallest distance from the source node as the next "current node" and repeat the above Done when all nodes are visited.

Data structures Distance to the source: a vertex-indexed array distTo[] such that distTo[v] is the length of the shortest known path from s to v Edges on the shortest paths tree: a parent- edge representation of a vertex-indexed array edgeTo[] where edgeTo[v] is the parent edge on the shortest path to v

Dijkstra’s algorithm

Graphs Simple graphs Algorithms – Depth-first search – Breadth-first search – shortest path – Connected components Directed graphs Weighted graphs Shortest path Minimum Spanning Tree

Depth-First Search (DFS) – Nonrecursive algorithm Push s onto a stack Repeat until the stack is empty: – remove the top vertex v, if not visited, mark as visited – add all v’s unvisited neighbors to the stack

Shortest Paths – Dijkstra’s Algorithm Assign to every node a distance value: set it to zero for source node and to infinity for all other nodes. Mark all nodes as unvisited. Set source node as current. For current node, consider all its unvisited neighbors and calculate their tentative distance. If this distance is less than the previously recorded distance, overwrite the distance (edge relaxation). Mark it as visited. Set the unvisited node with the smallest distance from the source node as the next "current node" and repeat the above Done when all nodes are visited.

Bonus Question Adjacency list A -- B, D B -- C C -- E, G D -- E, F E -- B F -- G G -- E Show the sequence of vertices visited using BFS and DFS Show the shortest path length (and path) from A to each vertex

MapQuest ? Shortest path for a single source-target pair Dijkstra algorithm can be used

Better Solution: Make a ‘hunch’! Use heuristics to guide the search – Heuristic: estimation or “hunch” of how to search for a solution We define a heuristic function: h(n) = “estimate of the cost of the cheapest path from the starting node to the goal node”

The A* Search A* is an algorithm that: – Uses heuristic to guide search – While ensuring that it will compute a path with minimum cost A* computes the function f(n) = g(n) + h(n) “actual cost” “estimated cost”

A* f(n) = g(n) + h(n) – g(n) = “cost from the starting node to reach n” – h(n) = “estimate of the cost of the cheapest path from n to the goal node” n g(n) h(n)

Properties of A* A* generates an optimal solution if h(n) is an admissible heuristic and the search space is a tree: – h(n) is admissible if it never overestimates the cost to reach the destination node A* generates an optimal solution if h(n) is a consistent heuristic and the search space is a graph: –h(n) is consistent if for every node n and for every successor node n’ of n: h(n) ≤ c(n,n’) + h(n’) n n’ d h(n) c(n,n’) h(n’) If h(n) is consistent then h(n) is admissible Frequently when h(n) is admissible, it is also consistent

Admissible Heuristics A heuristic is admissible if it is optimistic, estimating the cost to be smaller than it actually is. MapQuest: h(n) = “Euclidean distance to destination” is admissible as normally cities are not connected by roads that make straight lines

Project Option: Emory MapQuest Implement Dijkstra’s algorithm for finding a route between two cities Bonus: A* algorithm

Graphs Simple graphs Algorithms – Depth-first search – Breadth-first search – shortest path – Connected components Directed graphs Weighted graphs Shortest path Minimum Spanning Tree

Applications Phone/cable network design – minimum cost Approximation algorithms for NP-hard problems