Homework Assignment #3 Graph

Similar documents
CS Elementary Graph Algorithms

CS Elementary Graph Algorithms

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Chapter 22. Elementary Graph Algorithms

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.

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

Graph Algorithms (part 3 of CSC 282),

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Basic Graph Algorithms (CLRS B.4-B.5, )

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

CS4800: Algorithms & Data Jonathan Ullman

Graphs - II CS 2110, Spring 2016

Introduction to Algorithms. Lecture 11

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Total Score /1 /20 /41 /15 /23 Grader

Basic Graph Algorithms

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

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

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

Graph Representation

CSI 604 Elementary Graph Algorithms

Graph Algorithms (part 3 of CSC 282),

Spanning trees. Suppose you have a connected undirected graph

Graphs - II CS 2110, Spring 2016

Graph representation

DFS & STRONGLY CONNECTED COMPONENTS

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

W4231: Analysis of Algorithms

Graph: representation and traversal

Graph Search Methods. Graph Search Methods

csci 210: Data Structures Graph Traversals

Unit 2: Algorithmic Graph Theory

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

Outline. Graphs. Divide and Conquer.

CS 206 Introduction to Computer Science II

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Outline. Computer Science 331. Analysis of Prim's Algorithm

Graphs - II. Announcements. Where did I leave that book? Where did I leave that book? Where did I leave that book? CS 2110, Fall 2016

Algorithm Design and Analysis

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

Graphs & Digraphs Tuesday, November 06, 2007

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Outlines: Graphs Part-2

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

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

Homework 4 Even numbered problem solutions cs161 Summer 2009

Undirected Graphs. Hwansoo Han

tree follows. Game Trees

Graph Traversal CSCI Algorithms I. Andrew Rosenberg

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

ECE 242 HOMEWORK 5. In the figure below, one can go from node B to A but not from A to B.

Unweighted Graphs & Algorithms

Minimum Spanning Trees Ch 23 Traversing graphs

Lecture 6 Basic Graph Algorithms

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Data Structures and Algorithms. Werner Nutt

CSE 100: GRAPH ALGORITHMS

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

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

Representations of Graphs

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Algorithm Design and Analysis

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Practical Session No. 12 Graphs, BFS, DFS, Topological sort

Graph: representation and traversal

Algorithm Design and Analysis

Week 12: Minimum Spanning trees and Shortest Paths

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Announcements. HW3 is graded. Average is 81%

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

CSE 373: Practice Final

Data Structures and Algorithms. Chapter 7. Graphs

MST worksheet By Jim Xu

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Graph Search Methods. Graph Search Methods

Shortest path problems

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

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

Spanning Trees. Lecture 22 CS2110 Spring 2017

Homework No. 4 Answers

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Parallel Graph Algorithms

Lecture 3: Graphs and flows

COT 6405 Introduction to Theory of Algorithms

Minimum Spanning Tree

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Info 2950, Lecture 16

Lecture 9 Graph Traversal

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

Exam 3 Practice Problems

Math 15 - Spring Homework 5.2 Solutions

EECS 281 Homework 4 Key Fall 2004

Graph. Vertex. edge. Directed Graph. Undirected Graph

Graph Search. Adnan Aziz

Algorithm Design, Anal. & Imp., Homework 4 Solution

Transcription:

CISC 4080 Computer Algorithms Spring, 2019 Homework Assignment #3 Graph Some of the problems are adapted from problems in the book Introduction to Algorithms by Cormen, Leiserson and Rivest, and some are adapted from problems in Algorithms by Dasgupta, Papadimitrious and Vazirani. 1. Short questions (a) (True or False) During BFS traversal, all nodes stored in the queue are colored gray, and all gray nodes are in the queue. (b) (True or False) During BFS traversal of a graph, which of the following are possible contents of the queue. Why? Node A (d = 1), Node B (d = 1), Node C (d = 3), Node D (d = 2). Node A (d = 1), Node B (d = 1), Node C (d = 1), Node D (d = 1). Node A (d = 1), Node B (d = 1), Node C (d = 2), Node D (d = 2). Node A (d = 1), Node B (d = 1), Node A (d = 2), Node D (d = 3). (c) For the DFS traversal, what s the discover time and finish time of a node respectively? explain what they represent.) (i.e., (d) Explain how DFS can be used in topological sorting, and why the resulting order satisfies the requirement of topological sorting (i.e., for two vertices u, v, with a directed edge from u to v, u always appear before v in the ordering.

2. Perform a depth-first search and breadth-first search on the following graphs; whenever there is a choice of vertices (for example, in the outer loop of DFS, or when checking the adjacent nodes of a give node), pick the one that is alphabetically first. (This means that in DFS of the undirected graph, we will start from node A; and for example, when checking the adjacent nodes from H, we will see node D first). Draw the BFS and DFS trees formed by the edges that the search algorithms used to find each vertex. For DFS, give an example of 1) a pair of nodes u, v, so that [d[u], f[u]] is entirely within [d[v], f[v]], 2) a pair of nodes u, v, so that [d[u], f[u]] and [d[v], f[v]], 2) are disjoint (i.e., no overlap in time). undirected graph Directed graph 2

3. Pouring water. We have three containers whose size are 10 pints, 7 pints, and 4 pints, respectively. The 7-pint and 4-pint containers start out full of water, but the 10-pint container is initially empty. We are allowed one type of operation: pouring the contents of one container into another, stopping only when the source container is empty or the destination container is full. We want to know if there is a sequence of pourings that leaves exactly 2 pints in the 7- or 4-pint container. Model this as a graph problem: give a precise definition of the graph involved and state the specific question about this graph that needs to be answered. Write the pseudocode that return the list of adjacent nodes of a given node in this graph. // You can assume Node type stores three integers, // a10: amount of water in 10-pint container // a7: amount of water in 7-pint container // a4: amount of water in 4-pint container list<node> CalculateAdjacentNode (Node curnode) 3

What algorithm should be applied to solve the problem? Find the answer by applying the algorithm. 4

4. Give an efficient algorithm which takes as input a directed graph G = (V, E), and determines whether or not there is a vertex s V from which all other vertices are reachable. If the graph is undirected graph, would the algorithm be different? 5. Give an efficient algorithm which takes as input a undirected graph G = (V, E) and determines whether the graph is a tree, i.e., the graph is connected (i.e., every node is reachable from every other node) and there is no cycle. 5

6. Suppose Dijkstra s algorithm is run on the following graph, starting at node B. Draw a table showing the intermediate distance values of all the nodes at each iteration of the algorithm. Draw the final shortest-path tree. 6

7. Consider the following graph, and the problem of finding the minimum spanning tree of the graph. Run Prims algorithm; whenever there is a choice of nodes, always use reverse alphabetic ordering (e.g., start from node H). Draw a table showing the intermediate values of the cost array. Run Kruskals algorithm on the same graph. Show the edges that are added to the tree at each step. Whenever there are two candidate edges of same cost, the tie is broken arbitrarily. 7