-動態規劃. Getting started : Fibonacci Sequence Given initial value F(1) = 1, F(2) = 1. Recursive relation F(n) = F(n-1) + F(n-2) Given any number k, ask.

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

Types of Algorithms.
Dynamic Programming In this handout A shortest path example
Overview What is Dynamic Programming? A Sequence of 4 Steps
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Introduction to Algorithms
RAIK 283: Data Structures & Algorithms
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
Recursion.
Discrete Mathematics Recursion and Sequences
Analysis of Algorithms
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
1 Dynamic Programming Jose Rolim University of Geneva.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Advanced Counting Techniques
Dynamic Programming From An Excel Perspective. Dynamic Programming From An Excel Perspective Ranette Halverson, Richard Simpson, Catherine Stringfellow.
Department of Computer Science Data Structures Using C++ 2E Chapter 6: Recursion Learn about recursive Definitions Algorithms Functions Explore the base.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
ADA: 7. Dynamic Prog.1 Objective o introduce DP, its two hallmarks, and two major programming techniques o look at two examples: the fibonacci.
Fundamentals of Algorithms MCS - 2 Lecture # 7
Copyright © 2007 Pearson Education, Inc. Slide 8-1.
Copyright © 2011 Pearson Education, Inc. Slide
Dynamic Programming Chapter 15 Highlights Charles Tappert Seidenberg School of CSIS, Pace University.
Dynamic Programming.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2008 Dynamic programming  top-down vs. bottom-up  divide & conquer vs. dynamic programming  examples:
Dynamic Programming. What is dynamic programming? Break problem into subproblems Work backwards Can use ‘recursion’ ‘Programming’ - a mathematical term.
THE BENEFITS OF COMPUTERS Experimenting and Discovery in Mathematics.
Algorithm Paradigms High Level Approach To solving a Class of Problems.
CS.462 Artificial Intelligence SOMCHAI THANGSATHITYANGKUL Lecture 02 : Search.
LECTURE 40: SELECTION CSC 212 – Data Structures.  Sequence of Comparable elements available  Only care implementation has O(1) access time  Elements.
Dynamic Programming 21 August 2004 Presented by Eddy Chan Written by Ng Tung.
Data Structures & Algorithms Recursion and Trees Richard Newman.
Advanced Computer Architecture and Parallel Processing Rabie A. Ramadan http:
Recurrence Relation Models
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
1 Chapter 15-1 : Dynamic Programming I. 2 Divide-and-conquer strategy allows us to solve a big problem by handling only smaller sub-problems Some problems.
Dynamic Programming Day 3: Examples. Longest Common Subsequence Given two sequences of characters A, B Find the longest sequence C such that C is a subsequence.
Tuesday, April 30 Dynamic Programming – Recursion – Principle of Optimality Handouts: Lecture Notes.
Dynamic Programming (DP) By Denon. Outline Introduction Fibonacci Numbers (Review) Longest Common Subsequence (LCS) More formal view on DP Subset Sum.
A Different Solution  alternatively we can use the following algorithm: 1. if n == 0 done, otherwise I. print the string once II. print the string (n.
Dynamic Programming academy.zariba.com 1. Lecture Content 1.Fibonacci Numbers Revisited 2.Dynamic Programming 3.Examples 4.Homework 2.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Visual C++ Programming: Concepts and Projects Chapter 10A: Recursion (Concepts)
MA/CSSE 473 Day 11 Knuth interview Amortization (growable Array) Brute Force Examples.
Lub and glb Given a poset (S, · ), and two elements a 2 S and b 2 S, then the: –least upper bound (lub) is an element c such that a · c, b · c, and 8 d.
Dynamic Programming Csc 487/687 Computing for Bioinformatics.
All-pairs Shortest paths Transitive Closure
Design & Analysis of Algorithm Dynamic Programming
Lecture 5 Dynamic Programming
Dynamic Programming Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Least common subsequence:
Lecture 3.2: Induction and Strong Induction (contd.)
Intro to Recursion.
Lecture 5 Dynamic Programming
Dynamic Programming.
Data Structures & Algorithms
Lecture 3.2: Induction, and Strong Induction
Lecture 3.2: Induction and Strong Induction (contd.)
Lecture 3.2: Induction, and Strong Induction
Dynamic Programming.
Dynamic Programming Longest Path in a DAG, Yin Tat Lee
Chapter 15-1 : Dynamic Programming I
Dynamic Programming.
Advanced Programming Techniques
This is not an advertisement for the profession
Presentation transcript:

-動態規劃

Getting started : Fibonacci Sequence Given initial value F(1) = 1, F(2) = 1. Recursive relation F(n) = F(n-1) + F(n-2) Given any number k, ask F(k)

Fibonacci Sequence – Normal Solution Use recursive Continuity call the previous one Return while it reach known value – F(1), F(2) +intuitive -Time-consuming and memory-consuming →How many counts needed?

Fibonacci Sequence – Another Way Start from smaller one. Continuous add the last two to get a new one. Do until reach the value we want. +Faster -Not so easy to think at first glimpse

DP Elements Table Element Definition Recursive Formula Computing Sequence – Recursion – Mathematical Induction – Divide-and-Conquer ※ This part adapt from Pang-Feng’s PPT.

Relative Topics LCS / LIS /.. BFS / DFS Back Tracking Searching - More than once

Recall – LCS/LIS Given two or more sequences. Want to find the maximum length of common subsequence. If add increasing restriction? How about if we need to print the result out ?

Recall – BFS/DFS Given a plane, may refine region or not. Given starting point and ending point. How many ways to reach with least steps? (Means how many different shortest paths?) Visualize ?

An example : Spilt coin We have some values of coins now. $1, $5, … Unlimited amount for each kind. Given specific amount, find ways to combine. How if there are many test cases ?

Direct thought : Top down For example : $100, compose with $5 & $10 We may take $5 or $10 from it. → So ways(100) = ways(100-5) + ways(100-10) → ways(n) = ways(n-5) + ways(n-10) Use recursion until reach the known ones.

DP method : Bottom up Consider the value we can form from lower one. For example, if we have $5 and $10, we can add value by 5 or 10 through add one coin. How to use it ?

Related Exercises on Uva OJ Fibonacci Freeze Walking on the Safe Side Let Me Count The Ways Longest Common Subsequence History Grading The jackpot The Skyline Problem

References Pangfeng Liu, ACP-DP, 2004, NTU UVa Online Judge

Further Reading BFS,DFS and backtracking, by yugi340238, Visualized illustration about search. DP slider, by muming, Tiling problem, DP method of LIS. DP slider, by geniusdog, Tiling problem, formal definition and properties about dynamic programming.