1. Basic idea: Use smaller instances of the problem to find the solution of larger instances

Size: px
Start display at page:

Download "1. Basic idea: Use smaller instances of the problem to find the solution of larger instances"

Transcription

1 Chapter 8. Dynamic Programming CmSc Intro to Algorithms. Basic idea: Use smaller instances of the problem to find the solution of larger instances Example : Fibonacci numbers F = F = F n = F n- + F n- Recursion is exponential goes through all nodes in a tree of height n Dynamic solution: You need only the two previous values in order to compute the next number in the sequence F F Do n times: F F + F F F F F Output F Example : Computing a binomial coefficient (a + b) n = C(n,)a n + C(n,)a n- b + +C(n,k) a n-k b k + C(n,n) b n e.g (a + b) = C(,)a + C(,)a b +C(,) a b + C(,) a b + C(,) ab + C(,) b = a + a b + a b a b + a b + b Also: C(n,k): the number of combinations of k elements out of n elements: e.g. C(,) = {,}, {,}, {,} Formula: C(n,k) = n(n-)(n-) (n-k+) / k! = n! / ( k! (n-k)!) C(n,) = C(n,n) = Multiplication is a heavy operation Dynamic programming solution: Based on the relation C(n,k) = C(n-,k-) + C(n-,k) for n > k > ; C(n,) = C(n,n) =

2 k- k n- n k k k n- n- C(n-,k-) C(n-,k). n n C(n.k) n NOTE: recursive solution is possible but not efficient: Coeff(n,k) If k = or k = n return Else C(n,k) = c(n-,k) + c(n-,k-) Return C(n,k) Example: C(,) C(,) C(,) / \ C(,) C(,) C(,) C(,) / \ / \ / \ C(,) C(,) C(,) C(,) C(,) C(,) / \ / \ / \ C(,) C(,) C(,) C(,) C(,) C(,) Compare with Fibonacci recursion tree exponential complexity

3 Example : The Manhattan Tourist Problem Imagine seeking a path (from source to sink) to travel (only eastward and southward) with the most number of attractions () in the Manhattan grid Source Sink Goal: Find the longest path in a weighted grid. Input: A weighted grid G with two distinct vertices, one labeled source and the other labeled sink Output: A longest path in G from source to sink Each edge has a weight reflects the usefulness of going along that edge

4 source The greedy algorithm is not optimal: sink source promising start, but leads to bad choices! 8 sink

5 The greedy algorithm is given by a simple recursive program MT(n,m) x MT(n-,m)+ length of the edge from (n-,m) to (n,m) y MT(n,m-)+ length of the edge from (n,m-) to (n,m) return max{x,y} Dynamic programming approach: Calculate optimal path score for each vertex in the graph : Each vertex s score is the maximum of the prior vertices score plus the weight of the respective edge in between source j i S, = S, =

6 source i S, = - S, = 8 S, = 8 We continue in this way until the sink is reached Computing the score for a point (i,j) by the recurrence relation: s i, j = max s i-, j + weight of the edge between (i-, j) and (i, j) s i, j- + weight of the edge between (i, j-) and (i, j) The running time is n x m for a n by m grid (n = # of rows, m = # of columns) 6

7 Manhattan is not a perfect grid A A A B What about the diagonals? The score at point B is given by: S B = max( S A + weight of edge (A,B), S A + weight of edge (A,B), S A + weight of edge (A,B) ) In the general case, when a point x has several predecessors, computing the score for point x is given by the recurrence relation: S x = max y (S y + weight of edge (y,x) where y is a predecessor of x) Predecessors (x) set of vertices that have edges leading to x The running time for a graph G(V, E) is O(E) since each edge is evaluated once (V is the set of all vertices and E is the set of all edges) Traveling in the Grid The only hitch is that one must decide on the order in which visit the vertices By the time the vertex x is analyzed, the values sy for all its predecessors y should be computed otherwise we are in trouble. We need to traverse the vertices in some order The order is determined by the topological sort of the vertexes in the graph 7

8 . Characteristics. The problem can be divided into stages with a decision required at each stage.. Each stage has a number of states associated with it.. The decision at one stage transforms one state into a state in the next stage.. The optimal decision for state j does not depend on the optimal decision for stage j+. There exists a recursive relationship that identifies the optimal decision for stage j, given that stage j- has already been solved. 6. The initial stage must be solvable by itself.. Some other problems that can be solved with dynamic programming Computing the transitive closure of a directed graph - Warshall s algorithm All-pairs shortest paths problem Floyd s algorithm Optimal binary search trees The Knapsack problem The Coin Change problem DNA sequence alignments 8

9/29/09 Comp /Comp Fall

9/29/09 Comp /Comp Fall 9/29/9 Comp 9-9/Comp 79-9 Fall 29 1 So far we ve tried: A greedy algorithm that does not work for all inputs (it is incorrect) An exhaustive search algorithm that is correct, but can take a long time A

More information

Dynamic Programming Part I: Examples. Bioinfo I (Institut Pasteur de Montevideo) Dynamic Programming -class4- July 25th, / 77

Dynamic Programming Part I: Examples. Bioinfo I (Institut Pasteur de Montevideo) Dynamic Programming -class4- July 25th, / 77 Dynamic Programming Part I: Examples Bioinfo I (Institut Pasteur de Montevideo) Dynamic Programming -class4- July 25th, 2011 1 / 77 Dynamic Programming Recall: the Change Problem Other problems: Manhattan

More information

Dynamic Programming: Sequence alignment. CS 466 Saurabh Sinha

Dynamic Programming: Sequence alignment. CS 466 Saurabh Sinha Dynamic Programming: Sequence alignment CS 466 Saurabh Sinha DNA Sequence Comparison: First Success Story Finding sequence similarities with genes of known function is a common approach to infer a newly

More information

EECS 4425: Introductory Computational Bioinformatics Fall Suprakash Datta

EECS 4425: Introductory Computational Bioinformatics Fall Suprakash Datta EECS 4425: Introductory Computational Bioinformatics Fall 2018 Suprakash Datta datta [at] cse.yorku.ca Office: CSEB 3043 Phone: 416-736-2100 ext 77875 Course page: http://www.cse.yorku.ca/course/4425 Many

More information

Finding sequence similarities with genes of known function is a common approach to infer a newly sequenced gene s function

Finding sequence similarities with genes of known function is a common approach to infer a newly sequenced gene s function Outline DNA Sequence Comparison: First Success Stories Change Problem Manhattan Tourist Problem Longest Paths in Graphs Sequence Alignment Edit Distance Longest Common Subsequence Problem Dot Matrices

More information

Dynamic Programming: Edit Distance

Dynamic Programming: Edit Distance Dynamic Programming: Edit Distance Outline. DNA Sequence Comparison and CF. Change Problem. Manhattan Tourist Problem. Longest Paths in Graphs. Sequence Alignment 6. Edit Distance Section : DNA Sequence

More information

Pairwise Sequence alignment Basic Algorithms

Pairwise Sequence alignment Basic Algorithms Pairwise Sequence alignment Basic Algorithms Agenda - Previous Lesson: Minhala - + Biological Story on Biomolecular Sequences - + General Overview of Problems in Computational Biology - Reminder: Dynamic

More information

Dynamic Programming Comp 122, Fall 2004

Dynamic Programming Comp 122, Fall 2004 Dynamic Programming Comp 122, Fall 2004 Review: the previous lecture Principles of dynamic programming: optimization problems, optimal substructure property, overlapping subproblems, trade space for time,

More information

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming Computer Science 385 Design and Analysis of Algorithms Siena College Spring 29 Topic Notes: Dynamic Programming We next consider dynamic programming, a technique for designing algorithms to solve problems

More information

3/5/2018 Lecture15. Comparing Sequences. By Miguel Andrade at English Wikipedia.

3/5/2018 Lecture15. Comparing Sequences. By Miguel Andrade at English Wikipedia. 3/5/2018 Lecture15 Comparing Sequences By Miguel Andrade at English Wikipedia 1 http://localhost:8888/notebooks/comp555s18/lecture15.ipynb# 1/1 Sequence Similarity A common problem in Biology Insulin Protein

More information

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION 1. What is performance measurement? 2. What is an algorithm? 3. How the algorithm is good? 4. What are the

More information

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms Analysis of Algorithms Unit 4 - Analysis of well known Algorithms 1 Analysis of well known Algorithms Brute Force Algorithms Greedy Algorithms Divide and Conquer Algorithms Decrease and Conquer Algorithms

More information

Chapter 3, Algorithms Algorithms

Chapter 3, Algorithms Algorithms CSI 2350, Discrete Structures Chapter 3, Algorithms Young-Rae Cho Associate Professor Department of Computer Science Baylor University 3.1. Algorithms Definition A finite sequence of precise instructions

More information

DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.

More information

Lecture 16: Introduction to Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture 16: Introduction to Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY Lecture 16: Introduction to 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

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University Algorithms All-Pairs Shortest Paths Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr Contents Using single source shortest path algorithms Presents O(V 4 )-time algorithm, O(V 3 log V)-time algorithm,

More information

DynamicProgramming. September 17, 2018

DynamicProgramming. September 17, 2018 DynamicProgramming September 17, 2018 1 Lecture 11: Dynamic Programming CBIO (CSCI) 4835/6835: Introduction to Computational Biology 1.1 Overview and Objectives We ve so far discussed sequence alignment

More information

Chapter 6. Dynamic Programming

Chapter 6. Dynamic Programming Chapter 6 Dynamic Programming CS 573: Algorithms, Fall 203 September 2, 203 6. Maximum Weighted Independent Set in Trees 6..0. Maximum Weight Independent Set Problem Input Graph G = (V, E) and weights

More information

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting... Contents 1 Introduction... 1 1.1 What is Competitive Programming?... 1 1.1.1 Programming Contests.... 2 1.1.2 Tips for Practicing.... 3 1.2 About This Book... 3 1.3 CSES Problem Set... 5 1.4 Other Resources...

More information

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati MA 252: Data Structures and Algorithms Lecture 36 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The All-Pairs Shortest Paths Problem

More information

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016 CSCE 321/3201 Analysis and Design of Algorithms Prof. Amr Goneid Fall 2016 CSCE 321/3201 Analysis and Design of Algorithms Prof. Amr Goneid Course Resources Instructor: Prof. Amr Goneid E-mail: goneid@aucegypt.edu

More information

Dynamic Programming. Nothing to do with dynamic and nothing to do with programming.

Dynamic Programming. Nothing to do with dynamic and nothing to do with programming. Dynamic Programming Deliverables Dynamic Programming basics Binomial Coefficients Weighted Interval Scheduling Matrix Multiplication /1 Knapsack Longest Common Subsequence 6/12/212 6:56 PM copyright @

More information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)

More information

Dynamic Programming. Lecture Overview Introduction

Dynamic Programming. Lecture Overview Introduction Lecture 12 Dynamic Programming 12.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

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1 Directed Graphs Definitions. Representations. ADT s. Single Source Shortest Path Problem (Dijkstra, Bellman-Ford, Floyd-Warshall). Traversals for DGs. Parenthesis Lemma. DAGs. Strong Components. Topological

More information

More Dynamic Programming Floyd-Warshall Algorithm (All Pairs Shortest Path Problem)

More Dynamic Programming Floyd-Warshall Algorithm (All Pairs Shortest Path Problem) More Dynamic Programming Floyd-Warshall Algorithm (All Pairs Shortest Path Problem) A weighted graph is a collection of points(vertices) connected by lines(edges), where each edge has a weight(some real

More information

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Total Points: 60. Duration: 1hr

Total Points: 60. Duration: 1hr CS800 : Algorithms Fall 201 Nov 22, 201 Quiz 2 Practice Total Points: 0. Duration: 1hr 1. (,10) points Binary Heap. (a) The following is a sequence of elements presented to you (in order from left to right):

More information

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

UNIT 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 information

Subsequence Definition. CS 461, Lecture 8. Today s Outline. Example. Assume given sequence X = x 1, x 2,..., x m. Jared Saia University of New Mexico

Subsequence Definition. CS 461, Lecture 8. Today s Outline. Example. Assume given sequence X = x 1, x 2,..., x m. Jared Saia University of New Mexico Subsequence Definition CS 461, Lecture 8 Jared Saia University of New Mexico Assume given sequence X = x 1, x 2,..., x m Let Z = z 1, z 2,..., z l Then Z is a subsequence of X if there exists a strictly

More information

Encoding/Decoding, Counting graphs

Encoding/Decoding, Counting graphs Encoding/Decoding, Counting graphs Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ May 13, 2016 11-avoiding binary strings Let s consider

More information

Algorithm Design Paradigms

Algorithm Design Paradigms CmSc250 Intro to Algorithms Algorithm Design Paradigms Algorithm Design Paradigms: General approaches to the construction of efficient solutions to problems. Such methods are of interest because: They

More information

CS Algorithms and Complexity

CS Algorithms and Complexity CS 350 - Algorithms and Complexity Dynamic Programming Sean Anderson 2/20/18 Portland State University Table of contents 1. Homework 3 Solutions 2. Dynamic Programming 3. Problem of the Day 4. Application

More information

DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK DESIGN AND ANALYSIS OF ALGORITHMS UNIT1: INTRODUCTION OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study

More information

Data Structures and Algorithms (CSCI 340)

Data Structures and Algorithms (CSCI 340) University of Wisconsin Parkside Fall Semester 2008 Department of Computer Science Prof. Dr. F. Seutter Data Structures and Algorithms (CSCI 340) Homework Assignments The numbering of the problems refers

More information

Divide and Conquer Algorithms. Problem Set #3 is graded Problem Set #4 due on Thursday

Divide and Conquer Algorithms. Problem Set #3 is graded Problem Set #4 due on Thursday Divide and Conquer Algorithms Problem Set #3 is graded Problem Set #4 due on Thursday 1 The Essence of Divide and Conquer Divide problem into sub-problems Conquer by solving sub-problems recursively. If

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 Terrible Fibonacci Computation Fibonacci sequence: f = f(n) 2

More information

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014 AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 214 Q.2 a. Design an algorithm for computing gcd (m,n) using Euclid s algorithm. Apply the algorithm to find gcd (31415, 14142). ALGORITHM Euclid(m, n) //Computes

More information

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2006

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2006 University of New Mexico Department of Computer Science Final Examination CS 6 Data Structures and Algorithms Spring, 006 Name: Email: Print your name and email, neatly in the space provided above; print

More information

Recursive-Fib(n) if n=1 or n=2 then return 1 else return Recursive-Fib(n-1)+Recursive-Fib(n-2)

Recursive-Fib(n) if n=1 or n=2 then return 1 else return Recursive-Fib(n-1)+Recursive-Fib(n-2) Dynamic Programming Any recursive formula can be directly translated into recursive algorithms. However, sometimes the compiler will not implement the recursive algorithm very efficiently. When this is

More information

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

UNIT 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 information

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS 15CS43: DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK MODULE1 1. What is an algorithm? Write step by step procedure to write an algorithm. 2. What are the properties of an algorithm? Explain with an

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION Chendu College of Engineering & Technology (Approved by AICTE, New Delhi and Affiliated to Anna University) Zamin Endathur, Madurantakam, Kancheepuram District 603311 +91-44-27540091/92 www.ccet.org.in

More information

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms Professor Henry Carter Fall 2016 Recap Space-time tradeoffs allow for faster algorithms at the cost of space complexity

More information

Divide and Conquer. Bioinformatics: Issues and Algorithms. CSE Fall 2007 Lecture 12

Divide and Conquer. Bioinformatics: Issues and Algorithms. CSE Fall 2007 Lecture 12 Divide and Conquer Bioinformatics: Issues and Algorithms CSE 308-408 Fall 007 Lecture 1 Lopresti Fall 007 Lecture 1-1 - Outline MergeSort Finding mid-point in alignment matrix in linear space Linear space

More information

L.J. Institute of Engineering & Technology Semester: VIII (2016)

L.J. Institute of Engineering & Technology Semester: VIII (2016) Subject Name: Design & Analysis of Algorithm Subject Code:1810 Faculties: Mitesh Thakkar Sr. UNIT-1 Basics of Algorithms and Mathematics No 1 What is an algorithm? What do you mean by correct algorithm?

More information

Encoding/Decoding and Lower Bound for Sorting

Encoding/Decoding and Lower Bound for Sorting Encoding/Decoding and Lower Bound for Sorting CSE21 Winter 2017, Day 19 (B00), Day 13 (A00) March 1, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Announcements HW #7 assigned Due: Tuesday 2/7 11:59pm

More information

Lecture 6: Combinatorics Steven Skiena. skiena

Lecture 6: Combinatorics Steven Skiena.  skiena Lecture 6: Combinatorics Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Learning to Count Combinatorics problems are

More information

Quadratics. March 18, Quadratics.notebook. Groups of 4:

Quadratics. March 18, Quadratics.notebook. Groups of 4: Quadratics Groups of 4: For your equations: a) make a table of values b) plot the graph c) identify and label the: i) vertex ii) Axis of symmetry iii) x- and y-intercepts Group 1: Group 2 Group 3 1 What

More information

Lecture 12: Divide and Conquer Algorithms

Lecture 12: Divide and Conquer Algorithms Lecture 12: Divide and Conquer Algorithms Study Chapter 7.1 7.4 1 Divide and Conquer Algorithms Divide problem into sub-problems Conquer by solving sub-problems recursively. If the sub-problems are small

More information

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

( ) + n. ( ) = n 1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1 CSE 0 Name Test Summer 00 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose you are sorting millions of keys that consist of three decimal

More information

Review of course COMP-251B winter 2010

Review of course COMP-251B winter 2010 Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time

More information

Question Paper Code : 97044

Question Paper Code : 97044 Reg. No. : Question Paper Code : 97044 B.E./B.Tech. DEGREE EXAMINATION NOVEMBER/DECEMBER 2014 Third Semester Computer Science and Engineering CS 6301 PROGRAMMING AND DATA STRUCTURES-II (Regulation 2013)

More information

Model Answer. Section A Q.1 - (20 1=10) B.Tech. (Fifth Semester) Examination Analysis and Design of Algorithm (IT3105N) (Information Technology)

Model Answer. Section A Q.1 - (20 1=10) B.Tech. (Fifth Semester) Examination Analysis and Design of Algorithm (IT3105N) (Information Technology) B.Tech. (Fifth Semester) Examination 2013 Analysis and Design of Algorithm (IT3105N) (Information Technology) Model Answer. Section A Q.1 - (20 1=10) 1. Merge Sort uses approach to algorithm design. Ans:

More information

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18 CS 124 Quiz 2 Review 3/25/18 1 Format You will have 83 minutes to complete the exam. The exam may have true/false questions, multiple choice, example/counterexample problems, run-this-algorithm problems,

More information

Shortest path problems

Shortest 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 information

15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015

15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015 15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015 Dynamic Programming is a powerful technique that allows one to solve many different types

More information

Divide & Conquer Algorithms

Divide & Conquer Algorithms Divide & Conquer Algorithms Outline 1. MergeSort 2. Finding the middle vertex 3. Linear space sequence alignment 4. Block alignment 5. Four-Russians speedup 6. LCS in sub-quadratic time Section 1: MergeSort

More information

Divide & Conquer Algorithms

Divide & Conquer Algorithms Divide & Conquer Algorithms Outline MergeSort Finding the middle point in the alignment matrix in linear space Linear space sequence alignment Block Alignment Four-Russians speedup Constructing LCS in

More information

QB LECTURE #1: Algorithms and Dynamic Programming

QB LECTURE #1: Algorithms and Dynamic Programming QB LECTURE #1: Algorithms and Dynamic Programming Adam Siepel Nov. 16, 2015 2 Plan for Today Introduction to algorithms Simple algorithms and running time Dynamic programming Soon: sequence alignment 3

More information

Dynamic Programming 1

Dynamic Programming 1 Dynamic Programming 1 Jie Wang University of Massachusetts Lowell Department of Computer Science 1 I thank Prof. Zachary Kissel of Merrimack College for sharing his lecture notes with me; some of the examples

More information

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS420/520 Algorithm Analysis Spring 2009 Lecture 14 CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks

More information

Dynamic Programming Algorithms

Dynamic Programming Algorithms CSC 364S Notes University of Toronto, Fall 2003 Dynamic Programming Algorithms The setting is as follows. We wish to find a solution to a given problem which optimizes some quantity Q of interest; for

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures Chapter 9 Graph s 2 Definitions Definitions an undirected graph is a finite set

More information

1. Consider the 62-element set X consisting of the twenty-six letters (case sensitive) of the English

1. Consider the 62-element set X consisting of the twenty-six letters (case sensitive) of the English MATH 3012 Final Exam, May 3, 2013, WTT Student Name and ID Number 1. Consider the 62-element set X consisting of the twenty-six letters (case sensitive) of the English alphabet and the ten digits {0, 1,

More information

Optimization II: Dynamic Programming

Optimization II: Dynamic Programming Chapter 12 Optimization II: Dynamic Programming In the last chapter, we saw that greedy algorithms are efficient solutions to certain optimization problems. However, there are optimization problems for

More information

Analysis of Algorithms

Analysis of Algorithms Second Edition Design and Analysis of Algorithms Prabhakar Gupta Vineet Agarwal Manish Varshney Design and Analysis of ALGORITHMS SECOND EDITION PRABHAKAR GUPTA Professor, Computer Science and Engineering

More information

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences Section 5.3 1 Recursion 2 Recursion Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences Previously sequences were defined using a specific

More information

Binomial Coefficients

Binomial Coefficients Binomial Coefficients Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ May 6, 2016 Fixed-density Binary Strings How many length n binary strings

More information

Introduction to Algorithms Third Edition

Introduction to Algorithms Third Edition Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction

More information

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions: Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need

More information

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown.

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown. Introduction to Algorithms December 14, 2009 Massachusetts Institute of Technology 6.006 Fall 2009 Professors Srini Devadas and Constantinos (Costis) Daskalakis Final Exam Final Exam Do not open this quiz

More information

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1. D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1. DESIGN AND ANALYSIS OF ALGORITHM UNIT- I SECTION-A 2 MARKS 1. Define an algorithm? 2. Specify the criteria of algorithm? 3. What is Computational Procedure?

More information

******** Chapter-4 Dynamic programming

******** Chapter-4 Dynamic programming repeat end SHORT - PATHS Overall run time of algorithm is O ((n+ E ) log n) Example: ******** Chapter-4 Dynamic programming 4.1 The General Method Dynamic Programming: is an algorithm design method that

More information

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI & Introduction to TllG DCSISFI & mmmmm Analysis of Algorithms 3RD EDITION Anany Levitin Villa nova University International Edition contributions by Soumen Mukherjee RCC Institute of Information Technology

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures 3 Definitions an undirected graph G = (V, E) is a

More information

Recursively Defined Functions

Recursively Defined Functions Section 5.3 Recursively Defined Functions Definition: A recursive or inductive definition of a function consists of two steps. BASIS STEP: Specify the value of the function at zero. RECURSIVE STEP: Give

More information

The Shortest-Path Problem : G. Dantzig. 4-Shortest Paths Problems. The Shortest-Path Problem : G. Dantzig (continued)

The Shortest-Path Problem : G. Dantzig. 4-Shortest Paths Problems. The Shortest-Path Problem : G. Dantzig (continued) The Shortest-Path Problem : G. Dantzig 4-Shortest Paths Problems Bruno MARTIN, University of Nice - Sophia Antipolis mailto:bruno.martin@unice.fr http://deptinfo.unice.fr/~bmartin/mathmods Problem: Find

More information

Dynamic Programming: 1D Optimization. Dynamic Programming: 2D Optimization. Fibonacci Sequence. Crazy 8 s. Edit Distance

Dynamic Programming: 1D Optimization. Dynamic Programming: 2D Optimization. Fibonacci Sequence. Crazy 8 s. Edit Distance Dynamic Programming: 1D Optimization Fibonacci Sequence To efficiently calculate F [x], the xth element of the Fibonacci sequence, we can construct the array F from left to right (or bottom up ). We start

More information

Chapter 25: All-Pairs Shortest-Paths

Chapter 25: All-Pairs Shortest-Paths Chapter : All-Pairs Shortest-Paths When no negative edges Some Algorithms Using Dijkstra s algorithm: O(V ) Using Binary heap implementation: O(VE lg V) Using Fibonacci heap: O(VE + V log V) When no negative

More information

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here.

(a) Write code to do this without using any floating-point arithmetic. Efficiency is not a concern here. CS 146 Final Exam 1 Solutions by Dr. Beeson 1. Analysis of non-recursive algorithms. Consider the problem of counting the number of points with integer coordinates (x,y) on the circle of radius R, where

More information

Konigsberg Bridge Problem

Konigsberg Bridge Problem Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at

More information

CS2223 Algorithms B Term 2013 Exam 3 Solutions

CS2223 Algorithms B Term 2013 Exam 3 Solutions CS2223 Algorithms B Term 2013 Exam 3 Solutions Dec. 17, 2013 By Prof. Carolina Ruiz Dept. of Computer Science WPI PROBLEM I: Dynamic Programming (40 points) Consider the problem of calculating the binomial

More information

So far... Finished looking at lower bounds and linear sorts.

So far... Finished looking at lower bounds and linear sorts. So far... Finished looking at lower bounds and linear sorts. Next: Memoization -- Optimization problems - Dynamic programming A scheduling problem Matrix multiplication optimization Longest Common Subsequence

More information

5105 BHARATHIDASAN ENGINEERING COLLEGE

5105 BHARATHIDASAN ENGINEERING COLLEGE CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS II CSE/IT /IV SEMESTER UNIT I PART A 1. Design an algorithm to compute the area and circumference of a circle?(dec 2016) 2. Define recurrence relation? (Dec 2016)

More information

Dynamic 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 information

Unit-5 Dynamic Programming 2016

Unit-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 information

) $ f ( n) " %( g( n)

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

INTERNATIONAL INSTITUTE OF MANAGEMENT, ENGINEERING & TECHNOLOGY, JAIPUR (IIMET)

INTERNATIONAL INSTITUTE OF MANAGEMENT, ENGINEERING & TECHNOLOGY, JAIPUR (IIMET) INTERNATIONAL INSTITUTE OF MANAGEMENT, ENGINEERING & TECHNOLOGY, JAIPUR (IIMET) UNIT-1 Q.1 What is the significance of using notations in analysis of algorithm? Explain the various notations in brief?

More information

Solution Outlines. SWERC Judges SWERC SWERC Judges Solution Outlines SWERC / 39

Solution Outlines. SWERC Judges SWERC SWERC Judges Solution Outlines SWERC / 39 Outlines SWERC Judges SWERC 2010 SWERC Judges Outlines SWERC 2010 1 / 39 Statistics Problem 1 st team solving Time A - Lawnmower Dirt Collector 15 B - Periodic points C - Comparing answers Stack of Shorts

More information

A4B33ALG 2015/10 ALG 10. Dynamic programming. abbreviation: DP. Sources, overviews, examples see.

A4B33ALG 2015/10 ALG 10. Dynamic programming. abbreviation: DP. Sources, overviews, examples see. ALG 0 Dynamic programming abbreviation: DP Sources, overviews, examples see https://cw.fel.cvut.cz/wiki/courses/ae4balg/links 0 Dynamic programming DP is a general strategy applicable to many different

More information

All Pairs Shortest Paths

All Pairs Shortest Paths All Pairs Shortest Paths Given a directed, connected weighted graph G(V, E), for each edge u, v E, a weight w(u, v) is associated with the edge. The all pairs of shortest paths problem (APSP) is to find

More information

Catalan Numbers. Table 1: Balanced Parentheses

Catalan Numbers. Table 1: Balanced Parentheses Catalan Numbers Tom Davis tomrdavis@earthlink.net http://www.geometer.org/mathcircles November, 00 We begin with a set of problems that will be shown to be completely equivalent. The solution to each problem

More information

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I PART A(2MARKS) 1. What is an algorithm? 2. What is meant by open hashing? 3. Define Ω-notation 4.Define order of an algorithm. 5. Define O-notation

More information

Shortest Path Problem

Shortest Path Problem Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths

More information

Randomized Algorithms, Quicksort and Randomized Selection

Randomized Algorithms, Quicksort and Randomized Selection CMPS 2200 Fall 2017 Randomized Algorithms, Quicksort and Randomized Selection Carola Wenk Slides by Carola Wenk and Charles Leiserson CMPS 2200 Intro. to Algorithms 1 Deterministic Algorithms Runtime for

More information

END-TERM EXAMINATION

END-TERM EXAMINATION (Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information