CS330 Discussion 4 Spring 2017.

Slides:



Advertisements
Similar presentations
MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Advertisements

1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
MIT and James Orlin © Dynamic Programming 1 –Recursion –Principle of Optimality.
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
CSE115/ENGR160 Discrete Mathematics 02/28/12
1 Spanning Trees Lecture 20 CS2110 – Spring
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Pertemuan 23 : Penerapan Dinamik Programming (DP) Mata kuliah : K0164-Pemrograman vers 01.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Protein Structure Alignment by Incremental Combinatorial Extension (CE) of the Optimal Path Ilya N. Shindyalov, Philip E. Bourne.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Fundamentals of Algorithms MCS - 2 Lecture # 7
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Section 3.1. Section Summary Properties of Algorithms Algorithms for Searching and Sorting Greedy Algorithms Halting Problem.
CS 3343: Analysis of Algorithms Lecture 18: More Examples on Dynamic Programming.
PROBLEM-SOLVING TECHNIQUES Rocky K. C. Chang November 10, 2015.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Simplifying Dynamic Programming Jamil Saquer & Lloyd Smith Computer Science Department Missouri State University Springfield, MO USA.
NAME THAT ALGORITHM #2 HERE ARE SOME PROBLEMS. SOLVE THEM. GL HF.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
CSE15 Discrete Mathematics 03/06/17
Dynamic Programming 26-Apr-18.
Traveling Salesperson Problem
Optimal Play of the Farkle Dice Game
Data Structures Lab Algorithm Animation.
Shellsort.
Design & Analysis of Algorithm Dynamic Programming
CSC 172 DATA STRUCTURES.
Problem solving sequence
Generalized Permutations & Combinations: Selected Exercises
CS 3343: Analysis of Algorithms
Mathematical Induction II
Lecture 22 Complexity and Reductions
Greedy Algorithms Basic idea Connection to dynamic programming
JinJu Lee & Beatrice Seifert CSE 5311 Fall 2005 Week 10 (Nov 1 & 3)
CS100: Discrete structures
The Subset Sum Game Revisited
Intractable Problems Time-Bounded Turing Machines Classes P and NP
CS 3343: Analysis of Algorithms
Types of Algorithms.
Advanced Analysis of Algorithms
Unit-4: Dynamic Programming
Advanced Algorithms Analysis and Design
Dynamic Programming 1/15/2019 8:22 PM Dynamic Programming.
Graph Searching.
Lecture 6 Topics Greedy Algorithm
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
Matthew Renner, Trish Beeksma, Patch Kenny
Longest Common Subsequence
Dynamic Programming 23-Feb-19.
Chapter 14 & 15 Repeated Games.
Strike it out.
Chapter 14 & 15 Repeated Games.
Chapter 6 Network Flow Models.
Team Dont Block Me, National Taiwan University
Types of Algorithms.
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Lecture 5 Dynamic Programming
Factor Game Sample Game.
The Game of Estimation point 3 points 2 points
SHUT THE BOX! RULES INSTRUCTIONS PLAY.
Prims’ spanning tree algorithm
SHUT THE BOX! RULES INSTRUCTIONS PLAY.
Lecture 22 Complexity and Reductions
Algorithms Tutorial 27th Sept, 2019.
Presentation transcript:

CS330 Discussion 4 Spring 2017

DP Practice Problem 1 Suppose you have an infinite supply of 𝑚 different types of coins which are worth 𝑣 1 , 𝑣 2 ,… 𝑣 𝑚 cents respectively. Write an 𝑂(𝑚𝑁) algorithm which given 𝑣 1 , 𝑣 2 … 𝑣 𝑚 , determines whether it is possible to make exactly 𝑁 cents worth of change using these coins, and if so, what the minimum number of coins needed is. (Note, we can do better than 𝑂(𝑚𝑁), but that’s outside the scope of this discussion)

DP Practice Problem 2 In the “minimum jumps to the end” problem, you are given an 𝑛- element integer array 𝐷. A path 𝑃={ 𝑎 1 , 𝑎 2 … 𝑎 𝑘−1 ,𝑛} is a valid path if for each 𝑎 𝑖 , 𝑎 𝑖 ≤ 𝑎 𝑖−1 +𝐷[ 𝑎 𝑖−1 ] (where 𝑎 0 =1) Another way to think of it is, you start at element 1 of 𝐷. If you’re currently at element 𝑖, you may take a jump to any element from 𝑖+ 1 to 𝑖+D[𝑖]. For example, if 𝐷={2, 3, 1, 1, 5}, you could use 𝑃= 2, 5 𝑜𝑟 𝑃= 3, 4, 5 but not 𝑃={3, 5}. Here, the minimum jump count is 2. Write an algorithm to determine the minimum-length of any valid path, i.e. the minimum jumps to get to the end of 𝐷.

DP Practice Problem 3 Suppose you’re planning a bus route. There are 𝑛 possible stops along the route. The 𝑖th stop has 𝑥 𝑖 people who would ride the bus if it stopped there. Your goal is to choose some of these stops to maximize the number of people the bus can pick up. However, to make sure the bus makes it to its final destination on time, it can only stop at up to 𝑘:1≤𝑘<𝑛 of these stops. Furthermore, it should not stop at two adjacent stops. So, if you select the 𝑖th stop, you cannot select the 𝑖−1th or 𝑖+1th stop. Write an algorithm to determine the maximum number of people you can pick up. Report its runtime as well.

DP Practice Problem 4: Given two arrays 𝐴 and 𝐵, their longest common subsequence is the longest array 𝐶 such that the elements in 𝐶 exist in both 𝐴 and 𝐵, and their order is the same. For example, if 𝐴= 1, 4, 3, 2, 5 and 𝐵={1, 6, 3, 4, 2, 7}, the longest common subsequence is {1, 4, 2}. {1, 4, 3, 2} is not a valid subsequence because 3 does not come before 4 in 𝐵. Write an algorithm to determine the length of the longest common subsequence of 𝐴 and 𝐵.

DP Practice Problem 5a Consider the following two-player game: There is a line of coins with positive integer values 𝑣 1 , 𝑣 2 … 𝑣 𝑛 ( 𝑣 1 is the value of the left-most coin, 𝑣 2 is the value of the second left-most coin… 𝑣 𝑛 is the value of the right-most coin). Each player takes turns taking either the left-most or right-most remaining coin until all coins are gone. A player’s score is the sum of the values of the coins he has taken, minus the sum of the values of the coins his opponent has taken. A greedy solution is to always take the larger of the two end coins on each turn. Find an instance of this game where the greedy solution is not optimal against an optimally playing opponent. (Hint: The greedy solution is the optimal solution if there are three or less coins)

DP Practice Problem 5b Consider the game from the previous slide. Using dynamic programming, write an algorithm which, given the current sequence of coins 𝑣 1 , 𝑣 2 … 𝑣 𝑛 in the form of the array 𝑉, determines the score at the end of the game of the first player if both players play optimally, i.e. play to maximize their score at the end of the game. Report its runtime as well.