Solutions to Assessment
|
|
- Isaac Porter
- 5 years ago
- Views:
Transcription
1 Solutions to Assessment 1. Consider a directed weighted graph G containing 7 vertices, labelled from 1 to 7. Each edge in G is of the form e(i,j) where i<j(direction is from i to j). In addition, i is odd and j is even or i is even and j is odd. The Weight of e(i,j) is equal to i+j. Assume that we are computing the shortest path from 1 to all the remaining vertices using Dijkstra s algorithm. Which vertex will precede 7 in the shortest path from 1 to 7. Ans: 2 2.Suppose we run Dijkstra s single source shortest-path algorithm on the following edge weighted directed graph with vertex P as the source. What is the order of the vertices in which the shortest path is found by the algorithm? a) P, Q, R, S, T, U b) P, Q, R, U, S, T c) P, Q, R, U, T, S d) P, Q, T, R, U, S Answer: b 3. Dijkstra s single source shortest path algorithm when run from vertex a in the below graph, computes the correct shortest path distance to: a)only vertex a b)only vertices a,e,f,g,h c)only vertices a,b,c,d
2 d)all the vertices Ans: d 4. In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity by: a) Dijkstra's algorithm starting from A b) Warshall's algorithm c) Performing a dfs starting from S d) Performing a bfs starting from S Ans: d 5.Given a weighted graph where weights of all edges are unique (no two edge have same weights), there is always a unique shortest path from a source to destination in such a graph. a) Yes b) No Ans: b
3 Solutions to Programming Assignments Question 1: Implement Dijkstra s Algorithm in the method SSSP() given below. You are supposed to use two arrays dist[] and vertexincluded[] whose description is given in the comments in SSSP() method. The other required methods are given in the code and are explained in the comments. Input: The first line contains the number of vertices (V in number) and number of edges (E in number) separated by a space. E lines will follow, each containing 3 integers in the following format: v1 v2 d where, v1 and v2 are the two vertices having an undirected edge of length d between them. The vertex numbers will range from 0 to V-1. Output: A list of integers separated by spaces where the ith integer will denote the shortest distance of ith vertex from source. Note that indexing starts from 0 and 0 <= i < V. Constraints: 1<=V<=100 1<=E<=100 1<=d<=100 Test Cases: Public test cases: Input Output
4 Private test cases: Input Output
5
6 Solution: #include <stdio.h> #include <limits.h> #include<stdlib.h> /* This function returns the index of the vertex which is not included in the shortest path right now and has the smallest distance from the source. */ int minimumdist(int dist[], int vertexincluded[],int V) int min = INT_MAX, min_index; int v =0; for (v = 0; v < V; v++) if (vertexincluded[v] == 0 && dist[v] <= min) min = dist[v]; min_index = v; return min_index; /** This function prints the shortest distance of each vertex from the source separated by spaces */ int printsolution(int dist[], int V) int i=0; for ( i = 0; i < V-1; i++) printf("%d ",dist[i]); printf("%d",dist[v-1]); /** This function computes the shortest distance from the src.*/ void SSSP(int **graph, int src,int V) /** dist is the output array. dist[i] will hold the shortest distance from src to i. */ int dist[v]; /** vetexincluded[i] will be 1 if vertex i is included in shortest path tree or shortest distance from src to i is finalized */
7 int vertexincluded[v]; /** You are supposed to write your code from here **/ // Initialize all distances as INFINITE and vertexincluded[] as 0 int i; for (i = 0; i < V; i++) dist[i] = INT_MAX; vertexincluded[i] = 0; // Distance of source vertex from itself is always 0 dist[src] = 0; // Find shortest path for all vertices int count =0 ; for (count = 0; count < V-1; count++) // Pick the minimum distance vertex from the set of vertices not // yet processed. u is always equal to src in first iteration. int u = minimumdist(dist, vertexincluded,v); // Mark the picked vertex as processed vertexincluded[u] = 1; // Update dist value of the adjacent vertices of the picked vertex. int v; for (v = 0; v < V; v++) dist[v]) // Update dist[v] only if is not in vertexincluded, there is an edge from // u to v, and total weight of path from src to v through u is // smaller than current value of dist[v] if (!vertexincluded[v] && graph[u][v] && dist[u]!= INT_MAX && dist[u]+graph[u][v] < dist[v] = dist[u] + graph[u][v]; // print the constructed distance array printsolution(dist, V); // driver program to test above function int main() int V,E; int **graph;
8 // The vertices are numbered from 0 to V-1 scanf("%d %d",&v,&e); graph = (int **)malloc(sizeof(int *)*V); int i=0; for(i=0;i<v;i++) graph[i] = (int *)malloc(sizeof(int)*v); for(i=0;i<e;i++) int s,d,w; scanf("%d%d%d",&s,&d,&w); graph[s][d] = w; graph[d][s] = w; SSSP(graph, 0,V); return 0;
9 Question 2: In the kingdom of NPLand, there are a number of cities. One of them is the capital. Cities are connected to each other through straight roads. Every year a single person from each city gets a chance to work in the capital. The King organizes a competition every year. The rules are as follows: 1. The candidates will start running from their cities. (at the same times) 2. The entry into the capital will be permitted only for a fixed amount of time from when they all start running. 3. Whoever can enter the capital during that fixed time will surely be permitted to work there. Given the connections and the distances between the cities and the capital, the aim is to write a program to find out how many candidates can work in the capital. In designing the program you can assume that the candidates will find a route so that they can get to the capital before the entry closes, if there is one. Note that all the cities are numbered from 0 to V-1. Input: First line will contain the number of cities (V),number of roads (E) and time for which gate will be open (T). E lines will follow, each containing 3 integers in the format: city1 city2 t where, city1 and city2 are the two cities having a road between them and it takes time t to go from one city to another. Note that all the roads are bidirectional and the city numbered 0 is the capital city. Output: A single integer representing number of candidates that can work in the capital Constraints: 1<=V<=100 1<=E<=100 1<=t<=100 Test Cases: Public test cases: Input Output
10 Private test cases: Input Output
11
12 Solution: #include <stdio.h> #include <limits.h> #include<stdlib.h> /* This function returns the index of the vertex which is not included in the shortest path right now and has the smallest distance from the source. */ int minimumdist(int dist[], int vertexincluded[],int V) int min = INT_MAX, min_index; int v =0; for (v = 0; v < V; v++) if (vertexincluded[v] == 0 && dist[v] <= min) min = dist[v]; min_index = v; return min_index; /** This function computes the shortest distance from the src.*/ int SSSP(int **graph, int src,int V,int T) /** dist is the output array. dist[i] will hold the shortest distance from src to i. */ int dist[v];
13 /** vetexincluded[i] will be 1 if vertex i is included in shortest path tree or shortest distance from src to i is finalized */ int vertexincluded[v]; /** You are supposed to write your code from here **/ // Initialize all distances as INFINITE and stpset[] as 0 int i; for (i = 0; i < V; i++) dist[i] = INT_MAX; vertexincluded[i] = 0; // Distance of source vertex from itself is always 0 dist[src] = 0; // Find shortest path for all vertices int count =0 ; for (count = 0; count < V-1; count++) // Pick the minimum distance vertex from the set of vertices not // yet processed. u is always equal to src in first iteration. int u = minimumdist(dist, vertexincluded,v); // Mark the picked vertex as processed vertexincluded[u] = 1; // Update dist value of the adjacent vertices of the picked vertex. int v; for (v = 0; v < V; v++) // Update dist[v] only if is not in vertexincluded, there is an edge from // u to v, and total weight of path from src to v through u is // smaller than current value of dist[v] if (!vertexincluded[v] && graph[u][v] && dist[u]!= INT_MAX && dist[u]+graph[u][v] < dist[v]) dist[v] = dist[u] + graph[u][v]; // print the constructed distance array int entrycount=0; for(i=0;i<v;i++) if(dist[i] <= T) entrycount++; return entrycount;
14 // driver program to test above function int main() int V,E,T; int **graph; // The vertices are numbered from 0 to V-1 scanf("%d %d %d",&v,&e,&t); graph = (int **)malloc(sizeof(int*)*v); int i=0; for(i=0;i<v;i++) graph[i] = (int *)malloc(sizeof(int)*v); for(i=0;i<e;i++) int s,d,w; scanf("%d%d%d",&s,&d,&w); graph[s][d] = w; graph[d][s] = w; printf("%d",sssp(graph, 0,V,T)); return 0;
Description of The Algorithm
Description of The Algorithm Dijkstra s algorithm works by solving the sub-problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra
More informationPred 8 1. Dist. Pred
CS Graph Algorithms, Page Shortest Path Problem Task: given a graph G, find the shortest path from a vertex u to a vertex v. ffl If all edges are of the same length, then BFS will do. ffl But some times
More information2. 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.
1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:
More informationThe Shortest Path Problem
The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring
More informationDynamic Programming (Binomial Coefficient) 1) A binomial coefficient C(n, k) can be defined as the coefficient of X^k in the expansion of (1 + X)^n. 2) A binomial coefficient C(n, k) also gives the number
More informationUnit-5 Dynamic Programming 2016
5 Dynamic programming Overview, Applications - shortest path in graph, matrix multiplication, travelling salesman problem, Fibonacci Series. 20% 12 Origin: Richard Bellman, 1957 Programming referred to
More informationShortest path algorithms
Shortest path algorithms Research in Informatics Eleventh grade By: Karam Shbeb Supervisor: Eng. Ali Jnidi 2016/2017 Abstract: Finding the shortest path between two points or more is a very important problem
More informationDynamic Programming. December 15, CMPE 250 Dynamic Programming December 15, / 60
Dynamic Programming December 15, 2016 CMPE 250 Dynamic Programming December 15, 2016 1 / 60 Why Dynamic Programming Often recursive algorithms solve fairly difficult problems efficiently BUT in other cases
More informationCSE 100 Minimum Spanning Trees Prim s and Kruskal
CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:
More informationHomework Assignment #3 Graph
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
More informationComputational Methods in IS Research Fall Graph Algorithms Network Flow Problems
Computational Methods in IS Research Fall 2017 Graph Algorithms Network Flow Problems Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Network Flow Problems
More informationCSE 100: GRAPH ALGORITHMS
CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges
More informationIf the retrieving probability is equal for all programs, the Mean of Retrieval Time will be
.. The optimal storage tape: In this problem, the number of programs is N, the tape length is L, the length of the program LP j = P j, the programs will be stored in the sequence P, P,, P N, to retrieve
More informationGraphs. Bjarki Ágúst Guðmundsson Tómas Ken Magnússon Árangursrík forritun og lausn verkefna. School of Computer Science Reykjavík University
Graphs Bjarki Ágúst Guðmundsson Tómas Ken Magnússon Árangursrík forritun og lausn verkefna School of Computer Science Reykjavík University Today we re going to cover Minimum spanning tree Shortest paths
More information1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018
CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today
More informationDijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5
Dijkstra s Algorithm and Priority Queue Implementations CSE 101: Design and Analysis of Algorithms Lecture 5 CSE 101: Design and analysis of algorithms Dijkstra s algorithm and priority queue implementations
More informationTitle. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.
Title Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis Nesrine Damak Fakultät für Informatik TU München 20. September 2010 Nesrine Damak: Classical Shortest-Path Algorithms 1/ 35
More informationCS6301 Programming and Data Structures II Unit -5 REPRESENTATION OF GRAPHS Graph and its representations Graph is a data structure that consists of following two components: 1. A finite set of vertices
More informationProblem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?
Multiple-choice Problems: Problem 1. Which of the following is true of functions =100+log and =+log? a) = b) =Ω c) =Θ d) All of the above e) None of the above Problem 2. Which of the following is true
More information(Refer Slide Time: 00:18)
Programming, Data Structures and Algorithms Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 11 Lecture 58 Problem: single source shortest
More informationThe Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation
The Shortest Path Problem jla,jc@imm.dtu.dk Department of Management Engineering Technical University of Denmark The Shortest Path Problem Given a directed network G = (V,E,w) for which the underlying
More informationLecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009
Solving Shortest Path Problem: Dijkstra s Algorithm October 23, 2009 Outline Lecture 18 Focus on Dijkstra s Algorithm Importance: Where it has been used? Algorithm s general description Algorithm steps
More information1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018
CS 4 Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today
More informationUCSD CSE 101 MIDTERM 1, Winter 2008
UCSD CSE 101 MIDTERM 1, Winter 2008 Andrew B. Kahng / Evan Ettinger Feb 1, 2008 Name: }{{} Student ID: }{{} Read all of the following information before starting the exam. This test has 3 problems totaling
More informationAlgorithms and Theory of Computation. Lecture 3: Graph Algorithms
Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G
More informationLecture 14: Shortest Paths Steven Skiena
Lecture 14: Shortest Paths Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Suppose we are given
More informationCSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS
CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 5: SCC/BFS DECOMPOSITION There is a linear time algorithm that decomposes a directed graph into its
More informationGraph Algorithms (part 3 of CSC 282),
Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/10cs8 1 Schedule Homework is due Thursday, Oct 1. The QUIZ will be on Tuesday, Oct. 6. List of algorithms covered in the
More informationUNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:
UNIT 5 CSE 103 - Unit V- Graph GRAPH Graph is another important non-linear data structure. In tree Structure, there is a hierarchical relationship between, parent and children that is one-to-many relationship.
More informationGraph Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University
Graph Algorithms CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Network Flow How much freight can flow from Seattle to
More informationNew approach to find minimum spanning tree for undirected graphs
Chapter 4 New approach to find minimum spanning tree for undirected graphs 1. INTRODUCTION: In this chapter we find out a new approach to finding the minimum spanning tree for simple undirected graphs
More informationAddis Ababa University, Amist Kilo July 20, 2011 Algorithms and Programming for High Schoolers. Lecture 12
Addis Ababa University, Amist Kilo July 20, 2011 Algorithms and Programming for High Schoolers Single-source shortest paths: Lecture 12 We saw in Lab 10 that breadth-first search can be used to find the
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationCS170 Discussion Section 4: 9/18
CS170 Discussion Section 4: 9/18 1. Alien alphabet. Suppose you have a dictionary of an alien language which lists words in some sorted lexicographical ordering. For example, given the following list of
More informationEulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open)
Eulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open) circuit : vertices my repeat, edges cannot repeat (closed) path
More informationGraph Applications. Topological Sort Shortest Path Problems Spanning Trees. Data Structures 1 Graph Applications
Graph Applications Topological Sort Shortest Path Problems Spanning Trees Data Structures 1 Graph Applications Application: Topological Sort Given a set of jobs, courses, etc. with prerequisite constraints,
More informationDesign and Analysis of Algorithms
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length
More informationDesign and Analysis of Algorithms
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length
More informationBreadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2
Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there
More informationCSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s
CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 6: BFS and Dijkstra s BREADTH FIRST SEARCH (BFS) Given a graph G and a starting vertex s, BFS computes
More informationCMSC351 - Fall 2014, Homework #6
CMSC351 - Fall 2014, Homework #6 Due: December 12th at the start of class PRINT Name: Grades depend on neatness and clarity. Write your answers with enough detail about your approach and concepts used,
More informationUNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list
UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name
More informationGraph Algorithms (part 3 of CSC 282),
Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/11cs8 Homework problem sessions are in CSB 601, 6:1-7:1pm on Oct. (Wednesday), Oct. 1 (Wednesday), and on Oct. 19 (Wednesday);
More informationUNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD
UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset
More informationGraph Traversal. Section Dr. Chris Mayfield. Oct 24, Department of Computer Science James Madison University
Graph Traversal Section 4.1 4.2 Dr. Chris Mayfield Department of Computer Science James Madison University Oct 24, 2014 Reminder Portfolio 7 due in two weeks Submit four new problems (seven total) You
More informationCS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory
CS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory Dustin Tseng Mike Li Wednesday January 16, 2006 Dustin Tseng Mike Li: CS490: Problem Solving in Computer Science, Lecture
More informationCS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.
CS490 Quiz 1 NAME: STUDENT NO: SIGNATURE: This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed. Not all questions are of the same
More informationDist(Vertex u, Vertex v, Graph preprocessed) return u.dist v.dist
Design and Analysis of Algorithms 5th September, 2016 Practice Sheet 3 Solutions Sushant Agarwal Solutions 1. Given an edge-weighted undirected connected chain-graph G = (V, E), all vertices having degree
More informationSingle Source Shortest Path (SSSP) Problem
Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,
More information7 th Asia-Pacific Informatics Olympiad
7 th Asia-Pacific Informatics Olympiad Hosted by National University of Singapore, Singapore Saturday, 11 May, 2013 Task name ROBOTS TOLL TASKSAUTHOR Time Limit 1.5s 2.5s Not Applicable Heap Size 128MB
More informationAdvanced Java Concepts Unit 9: Graph Exercises
dvanced Java oncepts Unit : Graph Exercises. Which one of the following data structures would be best suited for representing a street map for pedestrians? graph with... a) undirected, unweighted edges.
More informationCS61BL. Lecture 5: Graphs Sorting
CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)
More informationDynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).
Lecture 13 Graph Algorithms I 13.1 Overview This is the first of several lectures on graph algorithms. We will see how simple algorithms like depth-first-search can be used in clever ways (for a problem
More informationCS 310 Advanced Data Structures and Algorithms
CS 0 Advanced Data Structures and Algorithms Weighted Graphs July 0, 07 Tong Wang UMass Boston CS 0 July 0, 07 / Weighted Graphs Each edge has a weight (cost) Edge-weighted graphs Mostly we consider only
More informationGraphs. 04/01/03 Lecture 20 1
Graphs Graphs model networks of various kinds: roads, highways, oil pipelines, airline routes, dependency relationships, etc. Graph G(V,E) VVertices or Nodes EEdges or Links: pairs of vertices Directed
More informationfrom notes written mostly by Dr. Carla Savage: All Rights Reserved
CSC 505, Fall 2000: Week 9 Objectives: learn about various issues related to finding shortest paths in graphs learn algorithms for the single-source shortest-path problem observe the relationship among
More informationLecture 10. Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes
Lecture 10 Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes Reading: Weiss, Chapter 9 Page 1 of 24 Midterm exam
More informationCS 125 Section #6 Graph Traversal and Linear Programs 10/13/14
CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there is one
More informationLEC13: SHORTEST PATH. CSE 373 Analysis of Algorithms Fall 2016 Instructor: Prof. Sael Lee. Lecture slide courtesy of Prof.
CSE 373 Analysis of Algorithms Fall 2016 Instructor: Prof. Sael Lee LEC13: SHORTEST PATH 1 SHORTEST PATHS Finding the shortest path between two nodes in a graph arises in many different applications: Transportation
More informationProblem A. Pyramid of Unit Cubes
Problem A Pyramid of Unit Cubes Consider a N-level pyramid built of unit cubes. An example for N=3 can be seen in the image below. Formally, a pyramid of size N has N levels, where the i-th level (counting
More informationCMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018
1 CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018 Shortest Paths The discussion in these notes captures the essence of Dijkstra s algorithm discussed in textbook
More informationOptimization II: Dynamic programming
Optimization II: Dynamic programming Ricardo Fukasawa rfukasawa@uwaterloo.ca Department of Combinatorics and Optimization Faculty of Mathematics University of Waterloo Nov 2, 2016 R. Fukasawa (C&O) Optimization
More informationAPPLIED GRAPH THEORY FILE. 7 th Semester MCE MCDTU.WORDPRESS.COM
APPLIED GRAPH THEORY FILE 7 th Semester MCE MCDTU.WORDPRESS.COM INDEX S.No. TOPIC DATE TEACHER S SIGNATURE 1. Write a program to find the number of vertices, even vertices, odd vertices and the number
More informationCS201 Discussion 14 ALLWORDLADDERS AND GALAXYTRIP
CS201 Discussion 14 ALLWORDLADDERS AND GALAXYTRIP Comparison to WordLadder To recap in WordLadder, we were trying to find if some path exists. Next word: Changing one letter For example, "lot" "log" "lot"
More informationUNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.
UNIT III TREES A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. Tree: A tree is a finite set of one or more nodes such that, there
More informationBasic Graph Definitions
CMSC 341 Graphs Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w V. V and E are sets, so each vertex
More informationGraphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College
Laura Toma Algorithms (csci2200), Bowdoin College Topics Weighted graphs each edge (u, v) has a weight denoted w(u, v) or w uv stored in the adjacency list or adjacency matrix The weight of a path p =
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Shortest paths in weighted graphs (Bellman-Ford, Floyd-Warshall) Outline 1 Shortest paths in graphs with
More informationLecture 10 Graph Algorithms
Lecture 10 Graph Algorithms Euiseong Seo (euiseong@skku.edu) 1 Graph Theory Study of the properties of graph structures It provides us with a language with which to talk about graphs Keys to solving problems
More informationShortest path problems
Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths
More informationCSC Intro to Intelligent Robotics, Spring Graphs
CSC 445 - Intro to Intelligent Robotics, Spring 2018 Graphs Graphs Definition: A graph G = (V, E) consists of a nonempty set V of vertices (or nodes) and a set E of edges. Each edge has either one or two
More informationGraph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph
Graphs Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs start Birmingham 60 Rugby fill pan with water add salt to water take egg from fridge
More informationClassical Shortest-Path Algorithms
DISTANCE PROBLEMS IN NETWORKS - THEORY AND PRACTICE Classical Shortest-Path Algorithms Nesrine Damak October 10, 2010 Abstract In this work, we present four algorithms for the shortest path problem. The
More informationGraphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131
Graphs Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - Faner 3131 1 Outline Introduction to Graphs Graph Traversals Finding a
More informationCSE 373 Final Exam 3/14/06 Sample Solution
Question 1. (6 points) A priority queue is a data structure that supports storing a set of values, each of which has an associated key. Each key-value pair is an entry in the priority queue. The basic
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra
More informationData Structures Brett Bernstein
Data Structures Brett Bernstein Final Review 1. Consider a binary tree of height k. (a) What is the maximum number of nodes? (b) What is the maximum number of leaves? (c) What is the minimum number of
More informationShortest Path Problem
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the shortest path is the path that has the smallest sum of its edge weights Dijkstra s
More informationAll Shortest Paths. Questions from exercises and exams
All Shortest Paths Questions from exercises and exams The Problem: G = (V, E, w) is a weighted directed graph. We want to find the shortest path between any pair of vertices in G. Example: find the distance
More informationIn this chapter, we consider some of the interesting problems for which the greedy technique works, but we start with few simple examples.
. Greedy Technique The greedy technique (also known as greedy strategy) is applicable to solving optimization problems; an optimization problem calls for finding a solution that achieves the optimal (minimum
More informationDynamic Programming. CSE 101: Design and Analysis of Algorithms Lecture 19
Dynamic Programming CSE 101: Design and Analysis of Algorithms Lecture 19 CSE 101: Design and analysis of algorithms Dynamic programming Reading: Chapter 6 Homework 7 is due Dec 6, 11:59 PM This Friday
More informationMystery Algorithm! ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v )
Mystery Algorithm! 0 2 ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v ) 3 1 4 7 6 5 mystery( v ) mark vertex v as visited PRINT v for each vertex w adjacent
More informationSolving problems on graph algorithms
Solving problems on graph algorithms Workshop Organized by: ACM Unit, Indian Statistical Institute, Kolkata. Tutorial-3 Date: 06.07.2017 Let G = (V, E) be an undirected graph. For a vertex v V, G {v} is
More informationCSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges
CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 8: Negative Edges DIJKSTRA S ALGORITHM WITH DIFFERENT PRIORITY QUEUES. Runtime of Array: O V 2 Runtime
More informationTA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009
TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009 Recitation #9 Question: For each of these problems about a subway system, describe a weighted graph model that can be used to solve the
More informationLecture 19 Shortest Path vs Spanning Tree Max-Flow Problem. October 25, 2009
Shortest Path vs Spanning Tree Max-Flow Problem October 25, 2009 Outline Lecture 19 Undirected Network Illustration of the difference between the shortest path tree and the spanning tree Modeling Dilemma:
More informationAlgorithms (VII) Yijia Chen Shanghai Jiaotong University
Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:
More informationShortest Paths. CSE 373 Data Structures Lecture 21
Shortest Paths CSE 7 Data Structures Lecture Readings and References Reading Section 9., Section 0.. Some slides based on: CSE 6 by S. Wolfman, 000 //0 Shortest Paths - Lecture Path A path is a list of
More informationShortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search
Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search 6.082 Fall 2006 Shortest Path Routing, Slide 1 Routing in an
More informationPresov. Kosice. Trencin
6 Graph algorithms 6.1 Graphs and their representation [BB 5.4-5.5 or CLRS2 B.4,22.1] Basic definitions Graph G is a pair (V, E), where V is a finite set (set of vertices) and E is a finite set of pairs
More informationHomework 4 Solutions
CS3510 Design & Analysis of Algorithms Section A Homework 4 Solutions Uploaded 4:00pm on Dec 6, 2017 Due: Monday Dec 4, 2017 This homework has a total of 3 problems on 4 pages. Solutions should be submitted
More informationCS Final - Review material
CS4800 Algorithms and Data Professor Fell Fall 2009 October 28, 2009 Old stuff CS 4800 - Final - Review material Big-O notation Though you won t be quizzed directly on Big-O notation, you should be able
More informationCSE 100: GRAPH ALGORITHMS
CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue
More informationAlgorithms (VII) Yijia Chen Shanghai Jiaotong University
Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:
More informationWDM Network Provisioning
IO2654 Optical Networking WDM Network Provisioning Paolo Monti Optical Networks Lab (ONLab), Communication Systems Department (COS) http://web.it.kth.se/~pmonti/ Some of the material is taken from the
More informationAlgorithms IV. Dynamic Programming. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms IV Dynamic Programming Guoqiang Li School of Software, Shanghai Jiao Tong University Dynamic Programming Shortest Paths in Dags, Revisited Shortest Paths in Dags, Revisited The special distinguishing
More informationShortest Paths and Minimum Spanning Trees
// hortest Paths and Minimum panning Trees avid Kauchak cs pring dmin an resubmit homeworks - for up to half credit back l ue by the end of the week Read book // // // // // Is ijkstra s algorithm correct?
More informationAnalysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, March 8, 2016 Outline 1 Recap Single-source shortest paths in graphs with real edge weights:
More informationQuiz 2 CS 3510 October 22, 2004
Quiz 2 CS 3510 October 22, 2004 NAME : (Remember to fill in your name!) For grading purposes, please leave blank: (1) Short Answer (40 points) (2) Cycle Length (20 points) (3) Bottleneck (20 points) (4)
More informationTraveling Salesman Problem Parallel Distributed Tree Search
Traveling Salesman Problem Parallel Distributed Tree Search Ned Nedialkov Dept. of Computing and Software McMaster University, Canada nedialk@mcmaster.ca March 2012 Outline Traveling salesman problem (TSP)
More information