Warshall s Algorithm: Transitive Closure

Size: px
Start display at page:

Download "Warshall s Algorithm: Transitive Closure"

Transcription

1 CS 0 Theory of Algorithms / CS 68 Algorithms in Bioinformaticsi Dynamic Programming Part II. Warshall s Algorithm: Transitive Closure Computes the transitive closure of a relation (Alternatively: all paths in a directed graph) Example of transitive closure: Design and Analysis of Algorithms - Chapter 8 8-

2 Warshall s Algorithm Main idea: a path exists between two vertices i, j, iff there is an edge from i to j; or there is a path from i to j going through vertex ; or there is a path from i to j going through vertex and/or ; or there is a path from i to j going through vertex,, and/or 3; or... there is a path from i to j going through any of the other vertices R R R R R Design and Analysis of Algorithms - Chapter 8 8- Warshall s Algorithm On the k th iteration, the algorithm determine if a path exists between two vertices i, j using just vertices among,,k allowed as intermediate { R (k-) [i,j] (path using just,,k-) R (k) [ij]= [i,j]= or (R (k-) [i,k] and R (k-) [k,j]) (path from i to k k and from k to i using just,,k-) i k th iteration j Design and Analysis of Algorithms - Chapter 8 8-3

3 Warshall s Algorithm: Transitive Closure Design and Analysis of Algorithms - Chapter 8 8- Warshall s Algorithm (matrix generation) Recurrence relating elements R (k) to elements of R (k-) is: R (k) [i,j] = R (k-) [i,j] or (R (k-) [i,k] and R (k-) [k,j]) It implies the following rules for generating R (k) from R (k-) : Rule If an element in row i and column j is in R (k-), it remains in R (k) Rule If an element in row i and column j is 0 in R (k-), it has to be changed to in R (k) if and only if the element in its row i and column k and the element in its column j and row k are both s inr R (k-)

4 Warshall s Algorithm: Transitive Closure Design and Analysis of Algorithms - Chapter Design and Analysis of Algorithms - Chapter 8 8-7

5 Warshall s Algorithm (pseudocode and analysis) Time efficiency: (n 3 ) Space efficiency: Matrices can be written over their predecessors Floyd s Algorithm: All pairs shortest paths Problem: In a weighted (di)graph, find shortest paths between every pair of vertices Same idea: construct solution through series of matrices D (0),, D (n) using increasing subsets of the vertices allowed as intermediate Example: Design and Analysis of Algorithms - Chapter 8 8-9

6 Floyd s Algorithm (matrix generation) On the k-th iteration, the algorithm determines shortest paths between every pair of vertices i, j that use only vertices among,,k as intermediate D (k) [i,j] = min {D (k-) [i,j], D (k-) [i,k] + D (k-) [k,j]} D (k-) [i,k] i D (k-) [i,j] j k D (k-) [k,j] Floyd s Algorithm: All pairs shortest paths Design and Analysis of Algorithms - Chapter 8 8-

7 Design and Analysis of Algorithms - Chapter 8 8- Floyd s Algorithm (pseudocode and analysis) Timeefficiency: ce cy: ( (n 3 ) Space efficiency: Matrices can be written over their predecessors

8 Knapsack Problem by DP Given n items of integer weights: w w w n values: v v v n a knapsack of integer capacity W find most valuable subset of the items that fit into the knapsack Consider instance defined by first i items and capacity j (j W). Let V[i,j] be optimal value of such instance. Then V[i,j]= max {V[i-,j], v i + V[i-,j- w i ]} if j- w i 0 V[i-,j] if j- w i < 0 Initial conditions: V[0,j] = 0 and V[i,0] = 0 Knapsack Problem by DP (example) Example: Knapsack of capacity W = 5 item weight value $ $0 3 3 $0 $5 capacity yjj w =, v = w =, v = 0 w 3 = 3, v 3 = 0 3 w =, v = 5?

9 Knapsack Problem V[i, j] = max (V[i, j], V[i, j w i ] + v i ) object i not used object i used Design and Analysis of Algorithms - Chapter Knapsack Problem V[i, j] = max (V[i, j], V[i, j w i ] + v i ) object i not used object i used Design and Analysis of Algorithms - Chapter 8 8-7

10 Knapsack Problem Memory Function Implement the recurrence recursively Do not calculate a value if it is not needed Do not recalculate a value Row 0 and column 0 of V are initialized to 0, other entries are - MFKnapsack(i, j) if V[i, j]< 0 if j < w[i] value MFKnapsack(i, j) else value max (MFKnapsack(i, j), MFKnapsack(i,j w[i]) + v[i]) V[i, j] value return V[i, j] Design and Analysis of Algorithms - Chapter Knapsack Problem Memory Function Design and Analysis of Algorithms - Chapter 8 8-9

Lecture 15: The Floyd-Warshall Algorithm

Lecture 15: The Floyd-Warshall Algorithm Lecture 15: The Floyd-Warshall Algorithm CLRS section 252 Outline of this Lecture Recalling the all-pairs shortest path problem Recalling the previous two solutions The Floyd-Warshall Algorithm 1 The All-Pairs

More information

Project Proposals. Your grade does not reflect how good a project you are proposing!

Project Proposals. Your grade does not reflect how good a project you are proposing! Project Proposals Your grade does not reflect how good a project you are proposing! It reflects how well you followed the instructions for the proposal! 1 What s the point of the Project? 1. Learn and

More information

9.3 Representing Relations

9.3 Representing Relations ICS 2: Discrete Mathematics II (Spring 205) 9.3 Representing Relations Representing Relations using Zero-One Matrices Let R be a relation from A = {a, a 2,..., a m } to B = {b, b 2,..., b n }. The relation

More information

All-Pairs Shortest Paths. All-Pairs Shortest Paths (Ch. 25) Overview of Dynamic Programming. Overview of Dynamic Programming. Slow-APSP Algorithm

All-Pairs Shortest Paths. All-Pairs Shortest Paths (Ch. 25) Overview of Dynamic Programming. Overview of Dynamic Programming. Slow-APSP Algorithm All-Pairs Shortest Paths (Ch. ) The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every pair of vertices

More information

Methods for solving exploration problems. 7- Exploration Problems. Greedy algorithm pattern. Exploration Problems

Methods for solving exploration problems. 7- Exploration Problems. Greedy algorithm pattern. Exploration Problems Methods for solving exploration problems 7- Exploration Problems Bruno MARTIN, University of Nice - Sophia Antipolis mailto:bruno.martin@unice.fr http://deptinfo.unice.fr/~bmartin/mathmods.html Greedy

More information

Discrete Mathematics. Chapter 8

Discrete Mathematics. Chapter 8 Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 2311: Discrete Mathematics Eng. Ahmed Abumarasa Discrete Mathematics Chapter 8 Relations 8.1: Relations

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : II / IV Section : CSE Subject Code : CS6402 Subject Name : DESIGN AND ANALYSIS OF ALGORITHM Degree & Branch : B.E C.S.E. UNIT-1 2 MARK QUESTIONS:

More information

Dynamic Programming. Lecture Overview Introduction

Dynamic Programming. Lecture Overview Introduction Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach

More information

KINGS COLLEGE OF ENGINEERING

KINGS COLLEGE OF ENGINEERING KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING UNIT I ALGORITHM ANALYSIS 1. What is an Algorithm? May/June 2006, Nov/Dec 2008 2. State the Euclid s algorithm for finding GCD

More information

Relations Graphical View

Relations Graphical View Relations Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Introduction Recall that a relation between elements of two sets is a subset of their Cartesian product (of ordered pairs). A binary

More information

Chapter 2 Integer Programming. Paragraph 1 Total Unimodularity

Chapter 2 Integer Programming. Paragraph 1 Total Unimodularity Chapter 2 Integer Programming Paragraph 1 Total Unimodularity What we did so far We studied algorithms for solving linear programs Simplex (primal, dual, and primal-dual) Ellipsoid Method (proving LP is

More information

Dynamic programming CS325

Dynamic programming CS325 Dynamic programming CS325 Shortest path in DAG DAG: directed acyclic graph A DAG can be linearized: all the nodes arranged in a line and the edges only goes from left to right (Chapter 3.3.2) Consider

More information

Elementary Graph Algorithms

Elementary Graph Algorithms Topics Elementary Graph Algorithms Representation of Graphs Breadth-first Search Depth-first Search Topological Sort Source: Introduction to Algorithms, Second Edition by Cormen, Leiserson, Rivest & Stein

More information

CLASS NOTES, CS W3137

CLASS NOTES, CS W3137 CLASS NOTES, CS W3137 1 Finding Shortest Paths: Dijkstra s Algorithm 1. We want to compute the shorterst path distance from a source node S to all other nodes. We associate lengths or costs on edges and

More information

Notes on Matrix Multiplication and the Transitive Closure

Notes on Matrix Multiplication and the Transitive Closure ICS 6D Due: Wednesday, February 25, 2015 Instructor: Sandy Irani Notes on Matrix Multiplication and the Transitive Closure An n m matrix over a set S is an array of elements from S with n rows and m columns.

More information

Approximation Algorithms

Approximation Algorithms Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms

More information

Totally Unimodular Matrices

Totally Unimodular Matrices Totally Unimodular Matrices m constraints, n variables Vertex solution: unique solution of n linearly independent tight inequalities Can be rewritten as: That is: Totally Unimodular Matrices Assuming all

More information

Algorithm Design Techniques

Algorithm Design Techniques Algorithm Design Techniques 0.1 Algorithm Design Techniques Various design techniques exist: Classifying algorithms based on design ideas or commonality. General-problem solving strategies. Brute force

More information

Dynamic Programming. Applies when the following Principle of Optimality

Dynamic Programming. Applies when the following Principle of Optimality Dynamic Programming Applies when the following Principle of Optimality holds: In an optimal sequence of decisions or choices, each subsequence must be optimal. Translation: There s a recursive solution.

More information

Catching Paul Revere, An Example Of The Analysis Of A Social Network.

Catching Paul Revere, An Example Of The Analysis Of A Social Network. Catching Paul Revere, An Example Of The Analysis Of A Social Network. Brian Borchers Department of Mathematics New Mexico Tech Socorro, NM 87801 borchers@nmt.edu Social Network Analysis A social network

More information

Course Notes for CS336: Graph Theory

Course Notes for CS336: Graph Theory Course Notes for CS336: Graph Theory Jayadev Misra The University of Texas at Austin 5/11/01 Contents 1 Introduction 1 1.1 Basics................................. 2 1.2 Elementary theorems.........................

More information

Graphs. Graph G=(V,E): representation

Graphs. Graph G=(V,E): representation Graphs G = (V,E) V the vertices of the graph {v 1, v 2,..., v n } E the edges; E a subset of V x V A cost function cij is the cost/ weight of the edge (v i, v j ) Graph G=(V,E): representation 1. Adjacency

More information

Depth First Search (DFS) And Edge Classification

Depth First Search (DFS) And Edge Classification Chapter epth First Search (FS) And Edge Classification. epth First Search.. efinition FS is a systematic method of visiting the vertices of a graph. Its general step requires that if we are currently visiting

More information

Graph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:

Graph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as: Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and

More information

Data Structures and Algorithms Written Examination

Data Structures and Algorithms Written Examination Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where

More information

Use the Huffman algorithm p. 388, build the following binary tree: g:13. f:8

Use the Huffman algorithm p. 388, build the following binary tree: g:13. f:8 9.53 Algorithms Name: SOLUTION Spring 22 Midterm Examination Open Book (CLRS), open notes, time period: 3 hours. Record answers in exam book. Turn in exam book(s) and examination question sheet.. (Ch 6

More information

Lab Manual. Algorithms Design (Pr) COT-311

Lab Manual. Algorithms Design (Pr) COT-311 Lab Manual Algorithms Design (Pr) COT-311 Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical / program Lab Teacher forms groups

More information

Greedy. Greedy. Greedy. Greedy Examples: Minimum Spanning Tree

Greedy. Greedy. Greedy. Greedy Examples: Minimum Spanning Tree This course - 91.503, Analysis of Algorithms - follows 91.0 (Undergraduate Analysis of Algorithms) and assumes the students familiar with the detailed contents of that course. We will not re-cover any

More information

CS2 Algorithms and Data Structures Note 11. Breadth-First Search and Shortest Paths

CS2 Algorithms and Data Structures Note 11. Breadth-First Search and Shortest Paths CS2 Algorithms and Data Structures Note 11 Breadth-First Search and Shortest Paths In this last lecture of the CS2 Algorithms and Data Structures thread we will consider the problem of computing distances

More information

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming All Pair Shortest Paths

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming All Pair Shortest Paths Algorithms and Theory of Computation Lecture 9: Dynamic Programming All Pair Shortest Paths Xiaohui Bei MAS 714 September 6, 2016 Nanyang Technological University MAS 714 September 6, 2016 1 / 20 Shortest

More information

Lecture 11: All-Pairs Shortest Paths

Lecture 11: All-Pairs Shortest Paths Lecture 11: All-Pairs Shortest Paths Introduction Different types of algorithms can be used to solve the all-pairs shortest paths problem: Dynamic programming Matrix multiplication Floyd-Warshall algorithm

More information

Dynamic Programming Algorithms 1

Dynamic Programming Algorithms 1 Dynamic Programming Algorithms 1 The setting is as follows. We wish to find a solution to a given problem which optimizes some quantity Q of interest; for example, we might wish to maximize profit or minimize

More information

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1. is compulsory and is of 20 marks. Attempt one out of two questions from remaining four units.

More information

Stanford University CS261: Optimization Handout 13 Luca Trevisan February 17, 2011

Stanford University CS261: Optimization Handout 13 Luca Trevisan February 17, 2011 Stanford University CS61: Optimization Handout 13 Luca Trevisan February 17, 011 Lecture 13 In which we describe a randomized algorithm for finding the minimum cut in an undirected graph. 1 Global Min-Cut

More information

1. a. What does dynamic programming have in common with divide-andconquer? b. What is a principal difference between the two techniques?

1. a. What does dynamic programming have in common with divide-andconquer? b. What is a principal difference between the two techniques? This file contains the exercises, hints, and solutions for Chapter 8 of the book Introduction to the Design and Analysis of Algorithms, 2nd edition, by A. Levitin. The problems that might be challenging

More information

Final Exam. Introduction to Algorithms December 20, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E.

Final Exam. Introduction to Algorithms December 20, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Introduction to Algorithms December 20, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Final Exam Final Exam Do not open this exam booklet

More information

All-Pairs Shortest Paths

All-Pairs Shortest Paths All-Pairs Shortest Paths Input: A directed graph G = (V, E) where each edge (v i, v j ) has a weight w(i, j). Output: A shortest path from u to v, for all u, v V. Weight of path: Given a path p =< v 1,...,

More information

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Why? A central concept in Computer Science. Algorithms are ubiquitous. Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online

More information

Exercises (not part of formal assignment, not graded)

Exercises (not part of formal assignment, not graded) CSE 101: Design and Analysis of Algorithms Homework 3 Winter 2016 Due: January 28, 2016 Exercises (not part of formal assignment, not graded) 1. DPV 5.2 (Modified). Suppose we want to find the minimum

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK IV SEMESTER CS6402-Design and Analysis of Algorithms Regulation 2013 Academic Year 2016

More information

3.1 Weighted Interval Scheduling Problem

3.1 Weighted Interval Scheduling Problem CS787: Advanced Algorithms Lecture 3: Dynamic Programming Just like divide and conquer algorithms, dynamic programming also attempts to break a problem into several smaller subproblems, solve these subproblems

More information

MATH20902: Discrete Maths, Solutions to Problem Set 6

MATH20902: Discrete Maths, Solutions to Problem Set 6 MATH20902: Discrete Maths, Solutions to Problem Set 6 These solutions, as well as the corresponding problems, are available at http://bit.ly/discretemancmaths. () (About metric spaces) Jungnickel points

More information

Netzwerkanalyse und -optimierung

Netzwerkanalyse und -optimierung Netzwerkanalyse und -optimierung Johannes Hatzl FH Kärnten WS 2010 J. Hatzl (FH) Netzwerkanalyse und -optimierung 2010 1 / 1 Graphs Definition A graph G = (V, E) is a pair of non-empty sets V and E {(i,

More information

(where C, X R and are column vectors)

(where C, X R and are column vectors) CS 05: Algorithms (Grad) What is a Linear Programming Problem? A linear program (LP) is a minimization problem where we are asked to minimize a given linear function subject to one or more linear inequality

More information

5.1 The String reconstruction problem

5.1 The String reconstruction problem CS125 Lecture 5 Fall 2015 5.1 The String reconstruction problem The greedy approach doesn t always work, as we have seen. It lacks flexibility; if at some point, it makes a wrong choice, it becomes stuck.

More information

CSE 191, Class Note 09 Computer Sci & Eng Dept SUNY Buffalo

CSE 191, Class Note 09 Computer Sci & Eng Dept SUNY Buffalo Introduction to Relations CSE 191, Class Note 09 Computer Sci & Eng Dept SUNY Buffalo c Xin He (University at Buffalo) CSE 191 Descrete Structures 1 / 57 Binary relation Let A and B be two sets. A binary

More information

11 Matrices and graphs: Transitive closure

11 Matrices and graphs: Transitive closure Matrices and graphs: ransitive closure 1 11 Matrices and graphs: ransitive closure Atomic versus structured objects. Directed versus undirected graphs. ransitive closure. Adjacency and connectivity matrix.

More information

Graph. Graph Theory. Adjacent, Nonadjacent, Incident. Degree of Graph

Graph. Graph Theory. Adjacent, Nonadjacent, Incident. Degree of Graph Graph Graph Theory Peter Lo A Graph (or undirected graph) G consists of a set V of vertices (or nodes) and a set E of edges (or arcs) such that each edge e E is associated with an unordered pair of vertices.

More information

Design and Analysis of algorithms

Design and Analysis of algorithms Design and Analysis of algorithms DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK SUBJECT CODE: CS1251 SUBJECT NAME: Design and Analysis of Algorithm YEAR : II SEM :IV UNIT I -ALGORITHM ANALYSIS

More information

Algorithm Design and Analysis, Fall 2011 Midterm Examination 135 points Time: 9:10am-12:10pm (180 minutes), Friday, November 18, 2011

Algorithm Design and Analysis, Fall 2011 Midterm Examination 135 points Time: 9:10am-12:10pm (180 minutes), Friday, November 18, 2011 Algorithm Design and Analysis, Fall 2011 Midterm Examination 135 points Time: 9:10am-12:10pm (180 minutes), Friday, November 18, 2011 Problem 1. In each of the following question, please specify if the

More information

Second Midterm Solutions

Second Midterm Solutions U.C. Berkeley CS70 : Algorithms Second Midterm Lecturers: Sanjam Garg and Prasad Raghavendra Nov 5, 205 Name: Second Midterm Solutions SID: GSI and section time: Read the questions carefully first. Be

More information

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013 Dynamic programming Doctoral course Optimization on graphs - Lecture.1 Giovanni Righini January 1 th, 201 Implicit enumeration Combinatorial optimization problems are in general NP-hard and we usually

More information

The Greedy Method. General Method. Most straightforward design technique

The Greedy Method. General Method. Most straightforward design technique The Greedy Method General Method Most straightforward design technique Most problems have n inputs Solution contains a subset of inputs that satisfies a given constraint Feasible solution: Any subset that

More information

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Dynamic Programming

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Dynamic Programming Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 25 Dynamic Programming Dynamic Programming Fibonacci sequence: f = f(n) 2 f = 3 f =2

More information

DATA STRUCTURES ALGORITHMS MOCK TEST DATA STRUCTURES ALGORITHMS MOCK TEST II

DATA STRUCTURES ALGORITHMS MOCK TEST DATA STRUCTURES ALGORITHMS MOCK TEST II http://www.tutorialspoint.com DATA STRUCTURES ALGORITHMS MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Data Structures Algorithms. You can download

More information

Directed Graphs BOS. Directed Graphs 1 ORD JFK SFO DFW LAX MIA

Directed Graphs BOS. Directed Graphs 1 ORD JFK SFO DFW LAX MIA Directed Graphs BOS ORD JFK SFO LAX DFW MIA Directed Graphs 1 Outline and Reading Reachability Directed DFS Strong connectivity Transitive closure The Floyd-Warshall Algorithm Directed Acyclic Graphs (DAG

More information

Dynamic Programming and Inclusion-Exclusion.

Dynamic Programming and Inclusion-Exclusion. 2MMD30: Graphs and Algorithms Lecture 6 by Jesper Nederlof, 26/02/206 Dynamic Programming and Inclusion-Exclusion. Dynamic programming is a very powerful techniques that you have probably seen already

More information

5 TRAVELING SALESMAN PROBLEM

5 TRAVELING SALESMAN PROBLEM 5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a Hamiltonian cycle of minimum length in a given complete weighted graph G=(V,E) with weights c ij =distance

More information

Lecture 7,8 (Sep 22 & 24, 2015):Facility Location, K-Center

Lecture 7,8 (Sep 22 & 24, 2015):Facility Location, K-Center ,8 CMPUT 675: Approximation Algorithms Fall 2015 Lecture 7,8 (Sep 22 & 24, 2015):Facility Location, K-Center Lecturer: Mohammad R. Salavatipour Scribe: Based on older notes 7.1 Uncapacitated Facility Location

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication Stephen Boyd EE103 Stanford University October 17, 2016 Outline Matrix multiplication Composition of linear functions Matrix powers QR factorization Matrix multiplication 2 Matrix

More information

Graph Algorithms. Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar

Graph Algorithms. Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text Introduction to Parallel Computing, Addison Wesley, 3. Topic Overview Definitions and Representation Minimum

More information

CSE 190, Great ideas in algorithms: Matrix multiplication

CSE 190, Great ideas in algorithms: Matrix multiplication CSE 190, Great ideas in algorithms: Matrix multiplication 1 Matrix multiplication Given two n n matrices A, B, compute their product C = AB using as few additions and multiplications as possible. That

More information

CS 253: Algorithms. Chapter 22. Graphs. Credit: Dr. George Bebis

CS 253: Algorithms. Chapter 22. Graphs. Credit: Dr. George Bebis CS 25: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis Graphs Definition = a set of nodes (vertices) with edges (links) between them. G = (V, E) - graph 1 2 V = set of vertices V = n E = set of edges

More information

Final Exam Solutions

Final Exam Solutions Introduction to Algorithms December 3, 005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 36 Final Exam Solutions Final Exam Score Distribution

More information

Matrix-Chain Multiplication

Matrix-Chain Multiplication Matrix-Chain Multiplication Let A be an n by m matrix, let B be an m by p matrix, then C = AB is an n by p matrix. C = AB can be computed in O(nmp) time, using traditional matrix multiplication. Suppose

More information

EE365: Shortest Paths

EE365: Shortest Paths EE365: Shortest Paths Deterministic optimal control The simplest shortest path algorithm Dijkstra s algorithm 1 Deterministic optimal control 2 Deterministic optimal control T 1 minimize g t(x t, u t)

More information

Introduction to NP-Complete Problems. February 15, 2008

Introduction to NP-Complete Problems. February 15, 2008 Introduction to NP-Complete Problems Shant Karakashian Rahul Puranda February 15, 2008 Definitions The 4-Step Proof Example 1: Vertex Cover Example 2: Jogger P, N P and N P-Complete Given a problem, it

More information

Algorithms: Divide and Conquer

Algorithms: Divide and Conquer Algorithms: Divide and Conquer Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Divide and Conquer Spring 2012 1 / 22 Integer Multiplication Input: integers I and J each represented by n bits. I + J

More information

Matrix Product. Matrix-Multiply (A, B) Cost of multiplying these matrices is p q r.

Matrix Product. Matrix-Multiply (A, B) Cost of multiplying these matrices is p q r. Dynamic Programming A powerful paradigm for algorithm design. Often leads to elegant and efficient algorithms when greedy or diide-and-conquer don t work. DP also breaks a problem into subproblems, but

More information

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8] Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)

More information

Greedy. Greedy. Greedy. Greedy. What is a Greedy Algorithm? Solves an optimization problem: the solution is best in some sense.

Greedy. Greedy. Greedy. Greedy. What is a Greedy Algorithm? Solves an optimization problem: the solution is best in some sense. A Comparison Divide & Conquer Dynamic Programming Algorithm View problem as collection of Recursive nature Independent overlapping typically sequential dependence Number of depends on partitioning factors

More information

All-Pairs Shortest Paths with Matrix Multiplication

All-Pairs Shortest Paths with Matrix Multiplication All-Pairs Shortest Paths with Matrix Multiplication Chandler Burfield March 15, 2013 Chandler Burfield APSP with Matrix Multiplication March 15, 2013 1 / 19 Outline 1 Seidel s algorithm 2 Faster Matrix

More information

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism CHAPTER 2 Graphs 1. Introduction to Graphs and Graph Isomorphism 1.1. The Graph Menagerie. Definition 1.1.1. A simple graph G = (V, E) consists of a set V of vertices and a set E of edges, represented

More information

Memoization/Dynamic Programming. The String reconstruction problem. CS125 Lecture 5 Fall 2016

Memoization/Dynamic Programming. The String reconstruction problem. CS125 Lecture 5 Fall 2016 CS125 Lecture 5 Fall 2016 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember

More information

Greedy Algorithms Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Greedy Algorithms Shabsi Walfish NYU - Fundamental Algorithms Summer 2006 Greedy Algorithms Greed Locally optimal decisions are called greedy Short sighted strategy (e.g. thinking only one move ahead in a game), usually easy to implement Generally efficient, but May not lead

More information

Design and Analysis of Algorithms April 20, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch

Design and Analysis of Algorithms April 20, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Design and Analysis of Algorithms April 20, 2015 Massachusetts Institute of Technology 6.046J/18.410J Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2 Solutions Quiz 2 Solutions Do not open this

More information

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1 5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1 General Integer Linear Program: (ILP) min c T x Ax b x 0 integer Assumption: A, b integer The integrality condition

More information

Digraphs. Directed Graphs. Digraph Application. Digraph Properties. A digraph is a graph whose edges are all directed.

Digraphs. Directed Graphs. Digraph Application. Digraph Properties. A digraph is a graph whose edges are all directed. igraphs irected Graphs LX FW OR MI OS digraph is a graph whose edges are all directed Short for directed graph pplications one-way streets flights task scheduling 2010 Goodrich, Tamassia irected Graphs

More information

CS2022/ MA 2201 Homework #5 Due Friday, 12/10

CS2022/ MA 2201 Homework #5 Due Friday, 12/10 CS/ MA Homework #5 Due Friday, / All questions worth 5 points #. Let R be the Congruence Modulo m relation on the integers: R = {(a,b) a = b (mod m); that is, m (a b) for some positive integer m}. a) If

More information

3.1 The existence of perfect matchings in bipartite graphs

3.1 The existence of perfect matchings in bipartite graphs 15-859(M): Randomized Algorithms Lecturer: Shuchi Chawla Topic: Finding Perfect Matchings Date: 20 Sep, 2004 Scribe: Viswanath Nagarajan 3.1 The existence of perfect matchings in bipartite graphs We will

More information

Relations --- Binary Relations. What is a relation?

Relations --- Binary Relations. What is a relation? Relations --- Binary Relations Debdeep Mukhopadhyay IIT Kharagpur What is a relation? The mathematical concept of relation is based on the common notion of relationships among objects: One box is heavier

More information

Review: Dynamic Programming

Review: Dynamic Programming Review: Dynamic Programming Dynamic Programming is a technique for algorithm design. It is a tabular method in which we break down the problem into subproblems, and place the solution to the subproblems

More information

Network Centrality. Based on materials by Lada Adamic, UMichigan

Network Centrality. Based on materials by Lada Adamic, UMichigan Network Centrality Based on materials by Lada Adamic, UMichigan Which nodes are most central? Definition of central varies by context/purpose. Local measure: degree Network Centrality Relative to rest

More information

Network (Tree) Topology Inference Based on Prüfer Sequence

Network (Tree) Topology Inference Based on Prüfer Sequence Network (Tree) Topology Inference Based on Prüfer Sequence C. Vanniarajan and Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology Madras Chennai 600036 vanniarajanc@hcl.in,

More information

1. Initialise Boolean array visited by setting all entries to FALSE 2. Initialise Stack S 3. for all v 2 V do 4. if not visited[v] then

1. Initialise Boolean array visited by setting all entries to FALSE 2. Initialise Stack S 3. for all v 2 V do 4. if not visited[v] then InfB Algorithms and Data Structures Note InfB Algorithms and Data Structures Note Graphs and DFS In this note, we turn to an alternative to BFS, which is Depth-First Search (DFS).. Depth-first search A

More information

1 NP-Completeness (continued)

1 NP-Completeness (continued) Mathematical Programming Lecture 27 OR 630 Fall 2006 November 30, 2006 adapted from notes by Omer Hancer 1 NP-Completeness (continued) Before starting on complexity theory, we talked about running times,

More information

Dynamic Programming Pattern

Dynamic Programming Pattern Dynamic Programming Pattern Yunsup Lee, Jike Chong, Youngmin Yi Computer Science Division, University of California at Berkeley {yunsup, jike, ymyi}@cs.berkeley.edu Problem Many optimization problems naturally

More information

Algorithms and Data Structures Final Exam 100 Points

Algorithms and Data Structures Final Exam 100 Points Algorithms and Data Structures Exam 100 Points Fill in the Blank (1 point each) 1. After many insertions and deletions in a hash table, it is possible that every unused node is marked as having been deleted.

More information

Lecture 12: Chain Matrix Multiplication

Lecture 12: Chain Matrix Multiplication Lecture 12: Chain Matrix Multiplication CLRS Section 15.2 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm for chain matrix

More information

Equivalence, Order, and Inductive Proof

Equivalence, Order, and Inductive Proof chapter 4 Equivalence, Order, and Inductive Proof Good order is the foundation of all things. Edmund Burke (729 797) Classifying things and ordering things are activities in which we all engage from time

More information

What are we going to learn?

What are we going to learn? What are we going to learn? Creating 2-D arrays Thinking about grain size Introducing point-to-point communications Reading and printing 2-D matrices Analyzing performance when computations and communications

More information

Dynamic Programming Part Three

Dynamic Programming Part Three Dynamic Programming Part Three Announcements Problem Set Five due right now, or due Wednesday with a late period. Problem Set Six out, due next Monday. Explore dynamic programming across different application

More information

GRAPH THEORY and APPLICATIONS. Trees

GRAPH THEORY and APPLICATIONS. Trees GRAPH THEORY and APPLICATIONS Trees Properties Tree: a connected graph with no cycle (acyclic) Forest: a graph with no cycle Paths are trees. Star: A tree consisting of one vertex adjacent to all the others.

More information

Computer Networks II Graph theory and routing algorithms

Computer Networks II Graph theory and routing algorithms Dipartimento di Informatica e Sistemistica Computer Networks II Graph theory and routing algorithms Luca Becchetti Luca.Becchetti@dis.uniroma1.it A.A. 2009/2010 Graphs G(V, E) where: V is vertex set E

More information

A Competitive Many-period Postman Problem With Varying Parameters

A Competitive Many-period Postman Problem With Varying Parameters Applied Mathematical Sciences, vol. 8, 2014, no. 146, 7249-7258 HIKARI Ltd, www.m-hikari.com http://dx.doi.org/10.12988/ams.2014.47591 A Competitive Many-period Postman Problem With Varying Parameters

More information

56:272 Integer Programming & Network Flows Final Exam Solutions -- Fall 99

56:272 Integer Programming & Network Flows Final Exam Solutions -- Fall 99 56:272 Integer Programming & Network Flows Final Exam Solutions -- Fall 99 Write your name on the first page, and initial the other pages. Answer all the multiple-choice questions and X of the remaining

More information

56:272 Integer Programming & Network Flows Final Exam -- Fall 99

56:272 Integer Programming & Network Flows Final Exam -- Fall 99 56:272 Integer Programming & Network Flows Final Exam -- Fall 99 Write your name on the first page, and initial the other pages. Answer all the multiple-choice questions and X of the remaining questions.

More information

aj if j = 0 max(m(j 1) + a j, a j ) else

aj if j = 0 max(m(j 1) + a j, a j ) else This list of problems goes approximately from easier problems to harder problems. The first few problems are for warmup and easier than anything you might see on the exam, but don t panic if you can t

More information

Linear Algebra and its Applications

Linear Algebra and its Applications Linear Algebra and its Applications 430 (2009) 2457 2463 Contents lists available at ScienceDirect Linear Algebra and its Applications journal homepage: www.elsevier.com/locate/laa Permutation matrices

More information

Applications of Minimum Spanning Trees

Applications of Minimum Spanning Trees Applications of Minimum Spanning Trees T. M. Murali February 17, 2009 Minimum Spanning Trees We motivated MSTs through the problem of finding a low-cost network connecting a set of nodes. MSTs are useful

More information