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

Size: px
Start display at page:

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

Transcription

1 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 subproblems are not independent. DP tabulates solutions of subproblems to aoid soling them again.

2 Dynamic Programming Typically applied to optimization problems: many feasible solutions; find one of optimal alue. Key is the principle of optimality: solution composed of optimal subproblem solutions. Example: Matrix Chain Product. A sequence M 1, M 2,..., M n of n matrices to be multiplied. Adjacent matrices must agree on dim.

3 Matrix Product Matrix-Multiply (A, B) 1. Let A be p q; let B be q r. 2. If dim of A and B don t agree, error. 3. for i = 1 to p 4. for j = 1 to r 5. C[i, j] = 0 6. for k = 1 to q 7. C[i, j] + = A[i, k] B[k, j] 8. return C. Cost of multiplying these matrices is p q r.

4 Matrix Chain Consider 4 matrices: M 1, M 2, M 3, M 4. We can compute the product in many different ways, depending on how we parenthesize. (M 1 (M 2 (M 3 M 4 ))) (M 1 ((M 2 M 3 )M 4 )) ((M 1 M 2 )(M 3 M 4 )) (((M 1 M 2 )M 3 )M 4 ) Different multiplication orders can lead to ery different total costs.

5 Matrix Chain Example: M 1 = , M 2 = 100 5, M 3 = Parentheses order ((M 1 M 2 )M 3 ) has cost = Parentheses order (M 1 (M 2 M 3 )) has cost = 75, 000!

6 Matrix Chain Input: a chain M 1, M 2,..., M n of n matrices. Matrix M i has size p i 1 p i, where i = 1, 2,..., n. Find optimal parentheses order to minimize cost of chain multiplying M i s. Checking all possible ways of parenthesizing is infeasible. There are roughly ( 2n n ) ways to put parentheses, which is of the order of 4 n!

7 Principle of Optimality Consider computing M 1 M 2... M n. Compute M 1,k Compute M k+1,n order. = M 1... M k, in some order. = M k+1... M n, in some Finally, compute M 1,n = M 1,k M k+1,n. Principle of Optimality: To optimize M 1,n, we must optimize M 1,k and M k+1,n too.

8 Recursie Solution A subproblem is subchain M i, M i+1..., M j. m[i, j] = optimal cost to multiply M i,..., M j. Use principle of optimality to determine m[i, j] recursiely. Clearly, m[i, i] = 0, for all i. If an algorithm computes M i, M i+1..., M j as (M i,..., M k ) (M k+1,..., M j ), then m[i, j] = m[i, k] + m[k + 1, j] + p i 1 p k p j

9 Recursie Solution m[i, j] = m[i, k] + m[k + 1, j] + p i 1 p k p j We don t know which k the optimal algorithm will use. But k must be between i and j 1. Thus, we can write: m[i, j] = min {m[i, k] + m[k + 1, j] + p i 1p k p j } i k<j

10 The DP Approach Thus, we wish to sole: m[i, j] = min {m[i, k] + m[k + 1, j] + p i 1p k p j } i k<j A direct recursie solution is exponential: brute force checking of all parentheses orders. What is the recurrence? What does it sole to? DP s insight: only a small number of subproblems actually occur, one per choice of i, j.

11 The DP Approach Naie recursion is exponential because it soles the same subproblem oer and oer again in different branches of recursion. DP aoids this wasted computation by organizing the subproblems differently: bottom up. Start with m[i, i] = 0, for all i. Next, we determine m[i, i + 1], and then m[i, i + 2], and so on.

12 The Algorithm Input: [p 0, p 1,..., p n ] the dimension ector of the matrix chain. Output: m[i, j], the optimal cost of multiplying each subchain M i... M j. Array s[i, j] stores the optimal k for each subchain.

13 The Algorithm Matrix-Chain-Multiply (p) 1. Set m[i, i] = 0, for i = 1, 2,..., n. 2. Set d = For all i, j such that j i = d, compute m[i, j] = min {m[i, k] + m[k + 1, j] + p i 1p k p j } i k<j Set s[i, j] = k, where k is the choice that gies min alue in aboe expression. 4. If d < n, increment d and repeat Step 3.

14 Illustration m array M1 = 30 x 35 j ,125 11,875 10, i M2 = 35 x 15 M3 = 15 x 5 M4 = 5 x ,375 7,125 5,375 7,875 4,375 2,500 3, M5 = 10 x 20 M6 = 20 x ,750 2, M1 M2 M3 M4 M5 M6

15 Illustration 1 2 j m array ,125 11,875 10,500 9,375 7,125 5,375 7,875 4,375 2,500 3,500 15,750 2, i 5 6 M1 M2 M3 M4 M5 M6 Computing m[2, 5]. min m[2, 2] + m[3, 5] + p 1 p 2 p 5 = = m[2, 3] + m[4, 5] + p 1 p 3 p 5 = = 7125 m[2, 4] + m[5, 5] + p 1 p 4 p 5 = = 11375

16 Finishing Up The algorithm clearly takes O(n 3 ) time. The m matrix only outputs the cost. The parentheses order from the s matrix. Matrix-Chain (M, s, i, j) 1. if j > i then 2. X Matrix-Chain (A, s, i, s[i, j]) 3. Y Matrix-Chain (A, s, s[i, j] + 1, j) 4. return X Y

17 Longest Common Subsequence Consider a string of characters: X = ABCBDAB. A subsequence is obtained by deleting some (any) characters of X. E.g. ABBB is a subsequence of X, as is ABD. But AABB is not a subsequence. Let X = (x 1, x 2,..., x m ) be a sequence. Z = (z 1, z 2,..., z k ) is subseq. of X if there is an index sequence (i 1,..., i k ) s.t. z j = x ij, for j = 1,..., k. Index sequence for ABBB is (1, 2, 4, 7).

18 Longest Common Subsequence Gien two sequences X and Y, find their longest common subsequence. If X = (A, B, C, B, D, A, B) and Y = (B, D, C, A, B, A), then (B, C, A) is a common sequence, but not LCS. (B, D, A, B) is a LCS. How do we find an LCS? Can some form of Greedy work? Suggestions?

19 Trial Ideas Greedy-1: Scan X. Find the first letter matching y 1 ; take it and continue. Problem: only matches prefix substrings of Y. Greedy-2: Find the most frequent letters of X; or sort the letters by their frequency. Try to match in frequency order. Problem: Frequency can be irreleant. E.g. suppose all letters of X are distinct.

20 Properties 2 m subsequences of X. LCS obeys the principle of optimality. Let X i = (x 1, x 2,..., x i ) be the i-long prefix of X. Examples: if X = (A, B, C, B, D, A, B), then X 2 = (A, B); X 5 = (A, B, C, B, D).

21 LCS Structure Suppose Z = (z 1, z 2,..., z k ) is a LCS of X and Y. Then, 1. If x m = y n, then z k = x m = y n and Z k 1 = LCS(X m 1, Y n 1 ). 2. If x m y n, then z k x m implies Z = LCS(X m 1, Y ). 3. If x m y n, then z k y n implies Z = LCS(X, Y n 1 ).

22 Recursie Solution Let c[i, j] = LCS(X i, Y j ) be the optimal solution for X i, Y j. Obiously, c[i, j] = 0 if either i = 0 or j = 0. In general, we hae the recurrence: c[i, j] = 0 if i or j = 0 c[i 1, j 1] + 1 if x i = y j max{c[i, j 1], c[i 1, j]} if x i y j

23 Algorithm A direct recursie solution is exponential: T (n) = 2T (n 1) + 1, which soles to 2 n. DP builds a table of subproblem solutions, bottom up. Starting from c[i, 0] and c[0, j], we compute c[1, j], c[2, j], etc.

24 Algorithm LCS-Length (X, Y ) c[i, 0] 0, c[0, j] 0, for all i, j; for i = 1 to m do for j = 1 to n do if x i = y j then c[i, j] c[i 1, j 1] + 1; b[i, j] D else if c[i 1, j] c[i, j 1] then c[i, j] c[i 1, j]; b[i, j] U else c[i, j] c[i, j 1]; b[i, j] L return b, c

25 LCS Algorithm LCS-Length (X, Y ) only computes the length of the common subsequence. By keeping track of matches, x i = y j, the LCS itself can be constructed.

26 LCS Algorithm PRINT-LCS(b, X, i, j) if i = 0 or j = 0 then return if b[i, j] = D then PRINT-LCS(b, X, i 1, j 1) print x i elseif b[i, j] = U then PRINT-LCS(b, X, i 1, j) else PRINT-LCS(b, X, i, j 1) Initial call is PRINT-LCS(b, X, X, Y ). By inspection, the time complexity of the algorithm is O(nm).

27 Optimal Polygon Triangulation Polygon is a piecewise linear closed cure. Only consecutie edges intersect, and they do so at ertices. P is conex if line segment xy is inside P wheneer x, y are inside

28 Optimal Polygon Triangulation Vertices in counter-clockwise order: 0, 1,..., n 1. Edges are i i+1, where n = 0. A chord i j joins two non-adjacent ertices. A triangulation is a set of chords that diide P into non-oerlapping triangles

29 Triangulation Problem Gien a conex polygon P = ( 0,..., n 1 ), and a weight function w on triangles, find a triangulation minimizing the total weight. Eery triangulation of a n-gon has n 2 triangles and n 3 chords

30 Optimal Triangulation One possible weight: w( i j k ) = i j + j k + k i But problem well defined for any weight function.

31 Greedy Strategies Greedy 1: Ring Heuristic. Go around each time, skipping one ertex; after logn rounds, done. Motiation joining closeby ertices. Not always optmal. Consider a flat, pancake like conex polygon. The optimal will put mostly ertical diagonals. Greedy s cost is roughly O(log n) times the perimeter.

32 Greedy Strategies Greedy 2: Always add shortest diagonal, consistent with preious selections. Counter-example by Lloyd. P = (A, B, C, D, E), where A = (0, 0); B = (50, 25); C = (80, 30); D = (125, 25); E = (160, 0). Edge lengths are BD = 75; CE < 86; AC < 86; BE > 112; AD > 127. Greedy puts BD, then forced to use BE, for total weight = 187. Optimal uses AC, CE, with total weight = 172.

33 Greedy Strategies GT (S) is within a constant factor of MW T (S) for conex polygons. For arbitrary point set triangulation, the ratio is Ω(n 1/2 ).

34 The Algorithm m[i, j] be the optimal cost of triangulating the subpolygon ( i, i+1,..., j ). Consider the with one side i j. Suppose the 3rd ertex is k. Then, the total cost of the triangulation is: m[i, j] = m[i, k] + m[k, j] + w( i j k )

35 The Algorithm Since we don t know k, we choose the one that minimizes this cost: m[i, j] = j min {m[i, k] + m[k + 1, j] + w( i j k )} i<k<j j 1 m[k, j] k i i+1 m[i, k]

36 All-Pairs Shortest Paths Gien G = (V, E), compute shortest path distances between all pairs of nodes. Run single-source shortest path algorithm from each node as root. Total complexity is O(nS(n, m)), where S(n, m) is the time for one shortest path iteration. If non-negatie edges, use Dijkstra s algorithm: O(m log n) time per iteration. With negatie edges, need to use Bellman-Ford algorithm: O(nm) time per iteration.

37 Floyd-Warshall Algorithm G = (V, E) has ertices {1, 2,..., n}. W is cost matrix. D is output distance matrix. algorithm Floyd-Warshall 1. D = W ; 2. for k = 1 to n 3. for i = 1 to n 4. for j = 1 to n 5. d ij = min{d ij, d ik + d kj } 6. return D.

38 Correctness Pij k : shortest path whose intermediate nodes are in {1, 2,..., k}. Goal is to compute Pij n, for all i, j. i P1 k P2 j Use Dynamic Programming. Two cases: 1. Vertex k not on Pij k. Then, P ij k = P k 1 ij. 2. Vertex k is on Pij k. Then, neither P 1 nor P 2 uses k as an intermediate node. in its interior. (Simplicity of Pij k.) Thus, P k ij = P k 1 ik + P k 1 kj

39 Correctness Recursie formula for P k ij : 1. If k = 0, P k ij = c ij. 2. If k > 0, d k ij = min{dk 1 ij, d k 1 ik + d k 1 kj }

40 Example Matrices D 0 and D 1 :

41 Example Matrices D 2 and D 5 :

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

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 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

Solutions to Homework 6

Solutions to Homework 6 Solutions to Homework 6 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 5.24 We want to find light spanning trees with certain special properties. Given is one example

More information

Unit 4: Dynamic Programming

Unit 4: Dynamic Programming Unit 4: Dynamic Programming Course contents: Assembly-line scheduling Matrix-chain multiplication Longest common subsequence Optimal binary search trees Applications: Rod cutting, optimal polygon triangulation,

More information

Warshall s Algorithm: Transitive Closure

Warshall s Algorithm: Transitive Closure 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

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

Vectors. Vector Multiplication

Vectors. Vector Multiplication Vectors Directed Line Segments and Geometric Vectors A line segment to which a direction has been assigned is called a directed line segment. The figure below shows a directed line segment form P to Q.

More information

Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY 11794 4400

Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY 11794 4400 Lecture 18: Applications of Dynamic Programming Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day

More information

Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711. List of topics Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

More information

3 Distance in Graphs. Brief outline of this lecture

3 Distance in Graphs. Brief outline of this lecture Distance in Graphs While the preios lectre stdied jst the connectiity properties of a graph, now we are going to inestigate how long (short, actally) a connection in a graph is. This natrally leads to

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

CMSC 451 Design and Analysis of Computer Algorithms 1

CMSC 451 Design and Analysis of Computer Algorithms 1 CMSC 4 Design and Analysis of Computer Algorithms David M. Mount Department of Computer Science University of Maryland Fall 003 Copyright, David M. Mount, 004, Dept. of Computer Science, University of

More information

Rotated Ellipses. And Their Intersections With Lines. Mark C. Hendricks, Ph.D. Copyright March 8, 2012

Rotated Ellipses. And Their Intersections With Lines. Mark C. Hendricks, Ph.D. Copyright March 8, 2012 Rotated Ellipses And Their Intersections With Lines b Mark C. Hendricks, Ph.D. Copright March 8, 0 Abstract: This paper addresses the mathematical equations for ellipses rotated at an angle and how to

More information

Problem Set 7 Solutions

Problem Set 7 Solutions 8 8 Introduction to Algorithms May 7, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Handout 25 Problem Set 7 Solutions This problem set is due in

More information

Linear Programming. March 14, 2014

Linear Programming. March 14, 2014 Linear Programming March 1, 01 Parts of this introduction to linear programming were adapted from Chapter 9 of Introduction to Algorithms, Second Edition, by Cormen, Leiserson, Rivest and Stein [1]. 1

More information

Near Optimal Solutions

Near Optimal Solutions Near Optimal Solutions Many important optimization problems are lacking efficient solutions. NP-Complete problems unlikely to have polynomial time solutions. Good heuristics important for such problems.

More information

Algebra Geometry Glossary. 90 angle

Algebra Geometry Glossary. 90 angle lgebra Geometry Glossary 1) acute angle an angle less than 90 acute angle 90 angle 2) acute triangle a triangle where all angles are less than 90 3) adjacent angles angles that share a common leg Example:

More information

Dynamic programming. Chapter 6. 6.1 Shortest paths in dags, revisited S C A B D E

Dynamic programming. Chapter 6. 6.1 Shortest paths in dags, revisited S C A B D E Chapter 6 Dynamic programming In the preceding chapters we have seen some elegant design principles such as divide-andconquer, graph exploration, and greedy choice that yield definitive algorithms for

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

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92. Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

More information

Group Theory and Molecular Symmetry

Group Theory and Molecular Symmetry Group Theory and Molecular Symmetry Molecular Symmetry Symmetry Elements and perations Identity element E - Apply E to object and nothing happens. bject is unmoed. Rotation axis C n - Rotation of object

More information

Scheduling Shop Scheduling. Tim Nieberg

Scheduling Shop Scheduling. Tim Nieberg Scheduling Shop Scheduling Tim Nieberg Shop models: General Introduction Remark: Consider non preemptive problems with regular objectives Notation Shop Problems: m machines, n jobs 1,..., n operations

More information

2.8 An application of Dynamic Programming to machine renewal

2.8 An application of Dynamic Programming to machine renewal ex-.6-. Foundations of Operations Research Prof. E. Amaldi.6 Shortest paths with nonnegative costs Given the following graph, find a set of shortest paths from node to all the other nodes, using Dijkstra

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU 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 information

LINES AND PLANES IN R 3

LINES AND PLANES IN R 3 LINES AND PLANES IN R 3 In this handout we will summarize the properties of the dot product and cross product and use them to present arious descriptions of lines and planes in three dimensional space.

More information

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION 2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION A world-coordinate area selected for display is called a window. An area on a display device to which a window is mapped is called a viewport. The window

More information

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity. 7 Catalan Numbers Thomas A. Dowling, Department of Mathematics, Ohio State Uni- Author: versity. Prerequisites: The prerequisites for this chapter are recursive definitions, basic counting principles,

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

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

More information

Shortest Path Algorithms

Shortest Path Algorithms Shortest Path Algorithms Jaehyun Park CS 97SI Stanford University June 29, 2015 Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Cross

More information

Analysis of Algorithms I: Optimal Binary Search Trees

Analysis of Algorithms I: Optimal Binary Search Trees Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search

More information

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle Page 1 of?? ENG rectangle Rectangle Spoiler Solution of SQUARE For start, let s solve a similar looking easier task: find the area of the largest square. All we have to do is pick two points A and B and

More information

5.1 Bipartite Matching

5.1 Bipartite Matching CS787: Advanced Algorithms Lecture 5: Applications of Network Flow In the last lecture, we looked at the problem of finding the maximum flow in a graph, and how it can be efficiently solved using the Ford-Fulkerson

More information

1 Symmetries of regular polyhedra

1 Symmetries of regular polyhedra 1230, notes 5 1 Symmetries of regular polyhedra Symmetry groups Recall: Group axioms: Suppose that (G, ) is a group and a, b, c are elements of G. Then (i) a b G (ii) (a b) c = a (b c) (iii) There is an

More information

Social Media Mining. Graph Essentials

Social Media Mining. Graph Essentials Graph Essentials Graph Basics Measures Graph and Essentials Metrics 2 2 Nodes and Edges A network is a graph nodes, actors, or vertices (plural of vertex) Connections, edges or ties Edge Node Measures

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

Shortest Inspection-Path. Queries in Simple Polygons

Shortest Inspection-Path. Queries in Simple Polygons Shortest Inspection-Path Queries in Simple Polygons Christian Knauer, Günter Rote B 05-05 April 2005 Shortest Inspection-Path Queries in Simple Polygons Christian Knauer, Günter Rote Institut für Informatik,

More information

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form Section 1.3 Matrix Products A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form (scalar #1)(quantity #1) + (scalar #2)(quantity #2) +...

More information

A Review And Evaluations Of Shortest Path Algorithms

A Review And Evaluations Of Shortest Path Algorithms A Review And Evaluations Of Shortest Path Algorithms Kairanbay Magzhan, Hajar Mat Jani Abstract: Nowadays, in computer networks, the routing is based on the shortest path problem. This will help in minimizing

More information

Triangulation by Ear Clipping

Triangulation by Ear Clipping Triangulation by Ear Clipping David Eberly Geometric Tools, LLC http://www.geometrictools.com/ Copyright c 1998-2016. All Rights Reserved. Created: November 18, 2002 Last Modified: August 16, 2015 Contents

More information

5.1 Midsegment Theorem and Coordinate Proof

5.1 Midsegment Theorem and Coordinate Proof 5.1 Midsegment Theorem and Coordinate Proof Obj.: Use properties of midsegments and write coordinate proofs. Key Vocabulary Midsegment of a triangle - A midsegment of a triangle is a segment that connects

More information

Minimum cost maximum flow, Minimum cost circulation, Cost/Capacity scaling

Minimum cost maximum flow, Minimum cost circulation, Cost/Capacity scaling 6.854 Advanced Algorithms Lecture 16: 10/11/2006 Lecturer: David Karger Scribe: Kermin Fleming and Chris Crutchfield, based on notes by Wendy Chu and Tudor Leu Minimum cost maximum flow, Minimum cost circulation,

More information

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors Chapter 9. General Matrices An n m matrix is an array a a a m a a a m... = [a ij]. a n a n a nm The matrix A has n row vectors and m column vectors row i (A) = [a i, a i,..., a im ] R m a j a j a nj col

More information

Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

More information

OPTIMAL BINARY SEARCH TREES

OPTIMAL BINARY SEARCH TREES OPTIMAL BINARY SEARCH TREES 1. PREPARATION BEFORE LAB DATA STRUCTURES An optimal binary search tree is a binary search tree for which the nodes are arranged on levels such that the tree cost is minimum.

More information

Analysis of Algorithms, I

Analysis of Algorithms, I Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications

More information

The Goldberg Rao Algorithm for the Maximum Flow Problem

The Goldberg Rao Algorithm for the Maximum Flow Problem The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }

More information

Data Structures Fibonacci Heaps, Amortized Analysis

Data Structures Fibonacci Heaps, Amortized Analysis Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

More information

3.1 Solving Systems Using Tables and Graphs

3.1 Solving Systems Using Tables and Graphs Algebra 2 Chapter 3 3.1 Solve Systems Using Tables & Graphs 3.1 Solving Systems Using Tables and Graphs A solution to a system of linear equations is an that makes all of the equations. To solve a system

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

Geometry Chapter 1. 1.1 Point (pt) 1.1 Coplanar (1.1) 1.1 Space (1.1) 1.2 Line Segment (seg) 1.2 Measure of a Segment

Geometry Chapter 1. 1.1 Point (pt) 1.1 Coplanar (1.1) 1.1 Space (1.1) 1.2 Line Segment (seg) 1.2 Measure of a Segment Geometry Chapter 1 Section Term 1.1 Point (pt) Definition A location. It is drawn as a dot, and named with a capital letter. It has no shape or size. undefined term 1.1 Line A line is made up of points

More information

Vector storage and access; algorithms in GIS. This is lecture 6

Vector storage and access; algorithms in GIS. This is lecture 6 Vector storage and access; algorithms in GIS This is lecture 6 Vector data storage and access Vectors are built from points, line and areas. (x,y) Surface: (x,y,z) Vector data access Access to vector

More information

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Computational Geometry. Lecture 1: Introduction and Convex Hulls Lecture 1: Introduction and convex hulls 1 Geometry: points, lines,... Plane (two-dimensional), R 2 Space (three-dimensional), R 3 Space (higher-dimensional), R d A point in the plane, 3-dimensional space,

More information

Lecture 3: Finding integer solutions to systems of linear equations

Lecture 3: Finding integer solutions to systems of linear equations Lecture 3: Finding integer solutions to systems of linear equations Algorithmic Number Theory (Fall 2014) Rutgers University Swastik Kopparty Scribe: Abhishek Bhrushundi 1 Overview The goal of this lecture

More information

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally Recurrence Relations Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations. A recurrence relation is an equation which

More information

Data Structures in Java. Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134

Data Structures in Java. Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134 Data Structures in Java Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134 Announcements Homework 4 on website No class on Tuesday Midterm grades almost done Review Indexing

More information

Conjectures. Chapter 2. Chapter 3

Conjectures. Chapter 2. Chapter 3 Conjectures Chapter 2 C-1 Linear Pair Conjecture If two angles form a linear pair, then the measures of the angles add up to 180. (Lesson 2.5) C-2 Vertical Angles Conjecture If two angles are vertical

More information

Solving Geometric Problems with the Rotating Calipers *

Solving Geometric Problems with the Rotating Calipers * Solving Geometric Problems with the Rotating Calipers * Godfried Toussaint School of Computer Science McGill University Montreal, Quebec, Canada ABSTRACT Shamos [1] recently showed that the diameter of

More information

VEHICLE ROUTING PROBLEM

VEHICLE ROUTING PROBLEM VEHICLE ROUTING PROBLEM Readings: E&M 0 Topics: versus TSP Solution methods Decision support systems for Relationship between TSP and Vehicle routing problem () is similar to the Traveling salesman problem

More information

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina stefano.martina@stud.unifi.it

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina stefano.martina@stud.unifi.it Seminar Path planning using Voronoi diagrams and B-Splines Stefano Martina stefano.martina@stud.unifi.it 23 may 2016 This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International

More information

Helvetic Coding Contest 2016

Helvetic Coding Contest 2016 Helvetic Coding Contest 6 Solution Sketches July, 6 A Collective Mindsets Author: Christian Kauth A Strategy: In a bottom-up approach, we can determine how many brains a zombie of a given rank N needs

More information

Linear Programming for Optimization. Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc.

Linear Programming for Optimization. Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc. 1. Introduction Linear Programming for Optimization Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc. 1.1 Definition Linear programming is the name of a branch of applied mathematics that

More information

CSC2420 Fall 2012: Algorithm Design, Analysis and Theory

CSC2420 Fall 2012: Algorithm Design, Analysis and Theory CSC2420 Fall 2012: Algorithm Design, Analysis and Theory Allan Borodin November 15, 2012; Lecture 10 1 / 27 Randomized online bipartite matching and the adwords problem. We briefly return to online algorithms

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

DATA ANALYSIS II. Matrix Algorithms

DATA ANALYSIS II. Matrix Algorithms DATA ANALYSIS II Matrix Algorithms Similarity Matrix Given a dataset D = {x i }, i=1,..,n consisting of n points in R d, let A denote the n n symmetric similarity matrix between the points, given as where

More information

Part 2: Community Detection

Part 2: Community Detection Chapter 8: Graph Data Part 2: Community Detection Based on Leskovec, Rajaraman, Ullman 2014: Mining of Massive Datasets Big Data Management and Analytics Outline Community Detection - Social networks -

More information

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list Scan-Line Fill Can also fill by maintaining a data structure of all intersections of polygons with scan lines Sort by scan line Fill each span vertex order generated by vertex list desired order Scan-Line

More information

CMPSCI611: Approximating MAX-CUT Lecture 20

CMPSCI611: Approximating MAX-CUT Lecture 20 CMPSCI611: Approximating MAX-CUT Lecture 20 For the next two lectures we ll be seeing examples of approximation algorithms for interesting NP-hard problems. Today we consider MAX-CUT, which we proved to

More information

Load balancing Static Load Balancing

Load balancing Static Load Balancing Chapter 7 Load Balancing and Termination Detection Load balancing used to distribute computations fairly across processors in order to obtain the highest possible execution speed. Termination detection

More information

1 Solving LPs: The Simplex Algorithm of George Dantzig

1 Solving LPs: The Simplex Algorithm of George Dantzig Solving LPs: The Simplex Algorithm of George Dantzig. Simplex Pivoting: Dictionary Format We illustrate a general solution procedure, called the simplex algorithm, by implementing it on a very simple example.

More information

Load Balancing and Termination Detection

Load Balancing and Termination Detection Chapter 7 Load Balancing and Termination Detection 1 Load balancing used to distribute computations fairly across processors in order to obtain the highest possible execution speed. Termination detection

More information

Applied Algorithm Design Lecture 5

Applied Algorithm Design Lecture 5 Applied Algorithm Design Lecture 5 Pietro Michiardi Eurecom Pietro Michiardi (Eurecom) Applied Algorithm Design Lecture 5 1 / 86 Approximation Algorithms Pietro Michiardi (Eurecom) Applied Algorithm Design

More information

Finding the Measure of Segments Examples

Finding the Measure of Segments Examples Finding the Measure of Segments Examples 1. In geometry, the distance between two points is used to define the measure of a segment. Segments can be defined by using the idea of betweenness. In the figure

More information

B490 Mining the Big Data. 2 Clustering

B490 Mining the Big Data. 2 Clustering B490 Mining the Big Data 2 Clustering Qin Zhang 1-1 Motivations Group together similar documents/webpages/images/people/proteins/products One of the most important problems in machine learning, pattern

More information

Arithmetic Coding: Introduction

Arithmetic Coding: Introduction Data Compression Arithmetic coding Arithmetic Coding: Introduction Allows using fractional parts of bits!! Used in PPM, JPEG/MPEG (as option), Bzip More time costly than Huffman, but integer implementation

More information

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws. Matrix Algebra A. Doerr Before reading the text or the following notes glance at the following list of basic matrix algebra laws. Some Basic Matrix Laws Assume the orders of the matrices are such that

More information

Chapter 11. 11.1 Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

Chapter 11. 11.1 Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling Approximation Algorithms Chapter Approximation Algorithms Q. Suppose I need to solve an NP-hard problem. What should I do? A. Theory says you're unlikely to find a poly-time algorithm. Must sacrifice one

More information

Guessing Game: NP-Complete?

Guessing Game: NP-Complete? Guessing Game: NP-Complete? 1. LONGEST-PATH: Given a graph G = (V, E), does there exists a simple path of length at least k edges? YES 2. SHORTEST-PATH: Given a graph G = (V, E), does there exists a simple

More information

CSC2420 Spring 2015: Lecture 3

CSC2420 Spring 2015: Lecture 3 CSC2420 Spring 2015: Lecture 3 Allan Borodin January 22, 2015 1 / 1 Announcements and todays agenda Assignment 1 due next Thursday. I may add one or two additional questions today or tomorrow. Todays agenda

More information

Linear Programming. April 12, 2005

Linear Programming. April 12, 2005 Linear Programming April 1, 005 Parts of this were adapted from Chapter 9 of i Introduction to Algorithms (Second Edition) /i by Cormen, Leiserson, Rivest and Stein. 1 What is linear programming? The first

More information

Vector Algebra. Addition: (A + B) + C = A + (B + C) (associative) Subtraction: A B = A + (-B)

Vector Algebra. Addition: (A + B) + C = A + (B + C) (associative) Subtraction: A B = A + (-B) Vector Algebra When dealing with scalars, the usual math operations (+, -, ) are sufficient to obtain any information needed. When dealing with ectors, the magnitudes can be operated on as scalars, but

More information

Discrete Optimization

Discrete Optimization Discrete Optimization [Chen, Batson, Dang: Applied integer Programming] Chapter 3 and 4.1-4.3 by Johan Högdahl and Victoria Svedberg Seminar 2, 2015-03-31 Todays presentation Chapter 3 Transforms using

More information

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions. Chapter 1 Vocabulary identity - A statement that equates two equivalent expressions. verbal model- A word equation that represents a real-life problem. algebraic expression - An expression with variables.

More information

2) Write in detail the issues in the design of code generator.

2) Write in detail the issues in the design of code generator. COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design Unit-IV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage

More information

Linear Programming Problems

Linear Programming Problems Linear Programming Problems Linear programming problems come up in many applications. In a linear programming problem, we have a function, called the objective function, which depends linearly on a number

More information

CSU Fresno Problem Solving Session. Geometry, 17 March 2012

CSU Fresno Problem Solving Session. Geometry, 17 March 2012 CSU Fresno Problem Solving Session Problem Solving Sessions website: http://zimmer.csufresno.edu/ mnogin/mfd-prep.html Math Field Day date: Saturday, April 21, 2012 Math Field Day website: http://www.csufresno.edu/math/news

More information

SAT Subject Math Level 2 Facts & Formulas

SAT Subject Math Level 2 Facts & Formulas Numbers, Sequences, Factors Integers:..., -3, -2, -1, 0, 1, 2, 3,... Reals: integers plus fractions, decimals, and irrationals ( 2, 3, π, etc.) Order Of Operations: Arithmetic Sequences: PEMDAS (Parentheses

More information

From Last Time: Remove (Delete) Operation

From Last Time: Remove (Delete) Operation CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

More information

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A. 1 Linear Transformations Prepared by: Robin Michelle King A transformation of an object is a change in position or dimension (or both) of the object. The resulting object after the transformation is called

More information

Lecture 1: Course overview, circuits, and formulas

Lecture 1: Course overview, circuits, and formulas Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik

More information

TSI College Level Math Practice Test

TSI College Level Math Practice Test TSI College Level Math Practice Test Tutorial Services Mission del Paso Campus. Factor the Following Polynomials 4 a. 6 8 b. c. 7 d. ab + a + b + 6 e. 9 f. 6 9. Perform the indicated operation a. ( +7y)

More information

Load Balancing and Termination Detection

Load Balancing and Termination Detection Chapter 7 slides7-1 Load Balancing and Termination Detection slides7-2 Load balancing used to distribute computations fairly across processors in order to obtain the highest possible execution speed. Termination

More information

Distance Degree Sequences for Network Analysis

Distance Degree Sequences for Network Analysis Universität Konstanz Computer & Information Science Algorithmics Group 15 Mar 2005 based on Palmer, Gibbons, and Faloutsos: ANF A Fast and Scalable Tool for Data Mining in Massive Graphs, SIGKDD 02. Motivation

More information

1. Prove that the empty set is a subset of every set.

1. Prove that the empty set is a subset of every set. 1. Prove that the empty set is a subset of every set. Basic Topology Written by Men-Gen Tsai email: b89902089@ntu.edu.tw Proof: For any element x of the empty set, x is also an element of every set since

More information

The Triangle and its Properties

The Triangle and its Properties THE TRINGLE ND ITS PROPERTIES 113 The Triangle and its Properties Chapter 6 6.1 INTRODUCTION triangle, you have seen, is a simple closed curve made of three line segments. It has three vertices, three

More information

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27 EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27 The Problem Given a set of N objects, do any two intersect? Objects could be lines, rectangles, circles, polygons, or other geometric objects Simple to

More information

International Journal of Advanced Research in Computer Science and Software Engineering

International Journal of Advanced Research in Computer Science and Software Engineering Volume 3, Issue 7, July 23 ISSN: 2277 28X International Journal of Advanced Research in Computer Science and Software Engineering Research Paper Available online at: www.ijarcsse.com Greedy Algorithm:

More information

Data Structures. Chapter 8

Data Structures. Chapter 8 Chapter 8 Data Structures Computer has to process lots and lots of data. To systematically process those data efficiently, those data are organized as a whole, appropriate for the application, called a

More information

DEGREE CONSTRAINED TRIANGULATION. Roshan Gyawali

DEGREE CONSTRAINED TRIANGULATION. Roshan Gyawali DEGREE CONSTRAINED TRIANGULATION by Roshan Gyawali Bachelor in Computer Engineering Institue of Engineering, Pulchowk Campus, Tribhuvan University, Kathmandu 2008 A thesis submitted in partial fulfillment

More information