TIM AU YEUNG HKOI 2012 Greedy. Try some cases Make a guess local optimum -> global optimum Not really a specific algorithm  Practice more  By feelings.

Slides:



Advertisements
Similar presentations
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Advertisements

Divide-and-Conquer CIS 606 Spring 2010.
Tiling Examples for X86 ISA Slides Selected from Radu Ruginas CS412/413 Lecture on Instruction Selection at Cornell.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Line Balancing Problem A B C 4.1mins D 1.7mins E 2.7 mins F 3.3 mins G 2.6 mins 2.2 mins 3.4 mins.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
The Greedy Method1. 2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1) Task Scheduling (§5.1.2) Minimum Spanning.
Chapter 5 Fundamental Algorithm Design Techniques.
Bowen Yu Programming Practice Midterm, 7/30/2013.
A problem Four people come to a river in the night. There is a narrow bridge, but it can only hold two people at a time. They have one torch and, because.
Greedy Algorithms Basic idea Connection to dynamic programming
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Progression In Calculations at Lyndhurst First School.
Recursion and Exhaustion Hong Kong Olympiad in Informatics 2009 Hackson Leung
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
Algebraic Expressions and Variables. Problem Solving Analyze the problem. Define your variable. Form an equation. Solve the equation Check the solution.
Linear Models Tony Dodd January 2007An Overview of State-of-the-Art Data Modelling Overview Linear models. Parameter estimation. Linear in the.
Increasing graph connectivity from 1 to 2 Guy Kortsarz Joint work with Even and Nutov.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
CSE 780 Algorithms Advanced Algorithms Greedy algorithm Job-select problem Greedy vs DP.
MAE 552 – Heuristic Optimization Lecture 5 February 1, 2002.
Fundamental Techniques
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
CS 206 Introduction to Computer Science II 02 / 25 / 2009 Instructor: Michael Eckmann.
What Does it Take to Learn 'Programming Thinking'? Anna Eckerdal, Anders Berglund Dept. of Information Technology Uppsala University Sweden.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
Section 1.3 Problem Solving 1. Steps to world problem solving process 1.Understand the Problem 2.Devise a plan 3.Carry out the plan 4.Look back 5.MAKE.
Bold Stroke January 13, 2003 Advanced Algorithms CS 539/441 OR In Search Of Efficient General Solutions Joe Hoffert
Compsci 201 Recitation 12 Professor Peck Jimmy Wei 11/15/2013.
Edge Covering problems with budget constrains By R. Gandhi and G. Kortsarz Presented by: Alantha Newman.
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.
1 ECE-517 Reinforcement Learning in Artificial Intelligence Lecture 7: Finite Horizon MDPs, Dynamic Programming Dr. Itamar Arel College of Engineering.
QUANTITATIVE ANALYSIS FOR MANAGERS TRANSPORTATION MODEL
1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014.
Mathematical Background and Linked Lists. 2 Iterative Algorithm for Sum Find the sum of the first n integers stored in an array v : sum (v[], n) temp_sum.
Gary Sham HKOI 2010 Greedy, Divide and Conquer. Greedy Algorithm Solve the problem by the “BEST” choice. To find the global optimal through local optimal.
Mathematical Proofs And how they are applied to Computer Olympiads.
Storage and Retrieval Structures by Ron Peterson.
1 Programming for Engineers in Python Autumn Lecture 12: Dynamic Programming.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Crossing Night 1 min 2 min 5 min 10 min each time, 2 persons share a torch they speed of slower person Target: all cross the bridge.
Greedy Algorithms Fundamental Data Structures and Algorithms Margaret Reid-Miller 25 March 2004.
Stem and Leaf Plots Stem and Leaf Plots emphasize place value.
LAB SESSION ONE DIMENSIONAL ARRAY.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
Y9 Booster Lesson 4. Objectives – what you should be able to do by the end of the lesson Use a calculator efficiently Use the function keys for powers,
Dr. Ron Lembke.  Situation: Assembly-line production.  Many tasks must be performed, and the sequence is flexible  Parts at each station same time.
DROPPING LOWEST GRADES MATC Math Club January 26, 2006 Jonathan Kane, Professor University of Wisconsin-Whitewater.
Greedy Algorithms Analysis of Algorithms.
Greedy Algorithms Seize the moment. Elements and Concerns Often an optimization problem Feasible solutions can be built in steps Quality of the next step.
HKOI 2004 Team Training Greedy Algorithms (Intermediate Level)
Problem Solving 1. Steps to world problem solving process 1. Understand the Problem 2. Devise a plan 3. Carry out the plan 4. Look back 5. MAKE SURE YOU.
Compsci 201 Recitation 12 Professor Peck Jimmy Wei 4/11/2014.
Currency Exchange Statistics + Suggested Solution.
Linear Models Tony Dodd. 21 January 2008Mathematics for Data Modelling: Linear Models Overview Linear models. Parameter estimation. Linear in the parameters.
Lecture on Design and Analysis of Computer Algorithm
Topic 25 Dynamic Programming
Relationship between soil pH and abundance of plant Species
Year 2 Autumn Term Week 4 Lesson 1
X y y = x2 - 3x Solutions of y = x2 - 3x y x –1 5 –2 –3 6 y = x2-3x.
Diffie-Hellman Key Exchange
Computational Thinking
Year 2 Autumn Term Week 4 Lesson 1
1 min each time, 2 persons share a torch they speed of slower person
Presentation transcript:

TIM AU YEUNG HKOI 2012 Greedy

Try some cases Make a guess local optimum -> global optimum Not really a specific algorithm  Practice more  By feelings

Example 1: Coins 7 kinds of coins: $0.1, $0.2, $0.5, $1, $2, $5, $10 Find minimum number of coins needed to pay $n Try n = 3.6  $2, $1, $0.5, $0.1 Try n = 18  $10, $5, $2, $1 Every time use the coin of highest value

Example 2: Subarray Sum Given a one-dimensional array of numbers (containing at least one positive number) Find the nonempty contiguous subarray which has the largest sum  Calculate maximum subarray ending at each position  simple example of DP (will be taught later) If all numbers are non-positive?

Example 3: Bridge and Torch Four people come to a river in the night. There is a narrow bridge, but it can only hold two people. Person A can cross the bridge in 1 minute, B in 2 minutes, C in 5 minutes, and D in 8 minutes. When two people cross the bridge together, they must move at the slower person's pace. What is the minimum time required for all four people to cross the river?

Example 3: Bridge and Torch N people  1) AB Go A Back, YZ Go B Back  2) AZ Go A Back, AY Go A Back N-2 people

Example 4: Yogurt factory POJ 2393 C_i: cost to produce one unit of yogurt in week i S: fee to store one unit of unused yogurt per week Y_i: units of yogurt demanded in week i (Yogurt produced in week i and already in storage, can be used to meet yogurt demand for that week)  Week i: sell yogurt produced in week j (j<=i)  minC = min(C_i, minC + S)

Example 5: Persistent Numbers POJ2325 Given a number n, find the smallest number that can reach n by repeatedly multiplying the digits e.g > 378 -> 168 -> 48 -> … 48 can be reached from 679 There may be No Solution!  Factorize n by 9, 8, 7, 6, 5, 4, 3, 2 in order  Distribute them from low-value digit to high-value digit

Greedy Practice List POJ 2709 POJ 1042 POJ 1065 POJ 2586 POJ 1328 POJ 1018 HKOJ 1019 HKOJ 1137 HKOJ 2014

If (Greedy_fails) Fail for boundary cases  Special solution deal with them Fail for many cases  Don’t be greedy  Think of other algorithm

Greedy Conclusion Guess Try some cases Hard to prove or disprove Easy to code Efficient Practice more!