COMPSCI 330 Design and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

A simple example finding the maximum of a set S of n numbers.
Greedy Algorithms Greed is good. (Some of the time)
Analysis of Algorithms
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Greedy Algorithms Basic idea Connection to dynamic programming
CSCE 3110 Data Structures & Algorithm Analysis
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
Lecture 34 CSE 331 Nov 30, Graded HW 8 On Wednesday.
Fundamental Techniques
1 Algorithm Design Techniques Greedy algorithms Divide and conquer Dynamic programming Randomized algorithms Backtracking.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Lecture 5 Dynamic Programming. Dynamic Programming Self-reducibility.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
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.
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.
Lecture 28 CSE 331 Nov 9, Mini project report due WED.
Foundations II: Data Structures and Algorithms
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
Lecture 8 CSE 331. Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis.
CSC317 1 So far so good, but can we do better? Yes, cheaper by halves... orkbook/cheaperbyhalf.html.
 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 2 Sorting (insertion Sort, Merge Sort)
Sorting Quick, Merge & Radix Divide-and-conquer Technique subproblem 2 of size n/2 subproblem 1 of size n/2 a solution to subproblem 1 a solution to.
HKOI 2004 Team Training Greedy Algorithms (Intermediate Level)
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Divide and Conquer. Problem Solution 4 Example.
Lecture 2: Divide and Conquer
Dynamic Programming Sequence of decisions. Problem state.
Algorithm Design Methods
Divide-and-Conquer 6/30/2018 9:16 AM
Lecture 5 Dynamic Programming
Unit 1. Sorting and Divide and Conquer
CS 3343: Analysis of Algorithms
Greedy Algorithms Basic idea Connection to dynamic programming
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Lecture 5 Dynamic Programming
Growth Functions Algorithms Lecture 8
CS 3343: Analysis of Algorithms
Objective of This Course
Algorithms and Data Structures Lecture III
Exam 2 LZW not on syllabus. 73% / 75%.
Divide-and-Conquer 7 2  9 4   2   4   7
Advanced Algorithms Analysis and Design
Chapter 15-1 : Dynamic Programming I
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
CS 1114: Sorting and selection (part two)
Divide-and-Conquer 7 2  9 4   2   4   7
Algorithm Design Methods
Trevor Brown CS 341: Algorithms Trevor Brown
Lecture 4 Dynamic Programming
Dynamic Programming II DP over Intervals
Lecture 6 Greedy Algorithms
Algorithm Design Methods
Lecture 2: Divide and Conquer
The Selection Problem.
Divide-and-Conquer 7 2  9 4   2   4   7
Advance Algorithm Dynamic Programming
Algorithm Design Methods
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Data Structures and Algorithms
Presentation transcript:

COMPSCI 330 Design and Analysis of Algorithms Midterm 1 Review

Basic Algorithm Design Techniques Analyzing running time Divide and conquer Dynamic Programming Greedy Common Theme: To solve a large, complicated problem, break it into many smaller sub-problems. Design algorithm Proof of correctness

How to know the right technique? In exam: it will be fairly obvious. In reality: you need experience. Worst case can try all three.

Divide and conquer Use when you can partition problems into unrelated subproblems. Key step: How to merge the solutions. Analysis: Use recursion trees for running time (or guess and do induction) Usually use induction to prove correctness.

Dynamic Programming Use if all subproblems are highly related, and there are not many subproblems you need to solve. Define a table for your subproblems. Consider all possibilities in the last step, write the recursion function for the table. Usually use induction to prove correctness (correctness is often straightforward and you only need to go through the formalities) Try implement the basic algorithms we covered in class.

Greedy Use when you can choose an obvious action to reduce the problem size. Proof is crucial --- you will lose many points if you just give a greedy algorithm, even if it’s correct. Analysis: Try to find counterexamples If you cannot find counterexamples, try prove the correctness by “proof by contradiction” Try to argue OPTIMAL must look like your solution.

Dynamic Programming and Greedy Both require treating the problem as making a sequence of decisions. A greedy problem can often be solved using DP as well, but the DP algorithm might be slower. Once you tweak a greedy problem (by adding weights/costs etc.) often the original greedy algorithm fails and you need to do DP. Get used to finding counter-examples – if you succeed, it means the algorithm is wrong; if you fail, it often gives intuition for proof.

Recursions (a) (You will not see this kind of problem as it is difficult, but just wanted to use it as an example)

Recursions (b) 𝑇 𝑛 =𝐹 log 2 𝑛 𝐹 𝑘 =2𝑇 2 𝑘−1 + 2 𝑘

Dynamic Programming Alice is playing a game where she controls the in-game character to catch pancakes. The character moves on a stage of length n. The character's location can be described by a number x in {1,…,n}. Let xt be the position of the character at time t. At each time step, Alice can move the character to the left (xt+1=xt-1), right (xt+1=xt+1) or do nothing (xt+1=xt). Alice already knows the game very well, so she knows a sequence of pairs (ti; pi) - This means at time ti there will be a pancake at location pi. The character starts at location 1 at time 0, and the game goes until time m. Please design an algorithm to find out how many pancakes Alice can get.

Example n = 5, m = 5 Pancakes ((1; 1); (2; 2); (3; 4); (3; 5); (4; 3); (4; 4); (5; 2)), Optimal solution: 4 Can get (1,1), (2,2), (4, 3) and (5,2) simultaneously

Greedy After scheduling for classrooms, let's schedule meeting rooms. Suppose there are n groups of people requesting for meeting rooms at the same time, and there are currently m rooms available. Group i has ni people, and room j has cj capacity. For group i, they are satisfied with any meeting room j whose capacity cj is at least ni, the number of people in the group. Design an algorithm that tries to find a meeting room for as many groups as possible.

Exam Format is very similar to the practice exam It would be quite obvious what technique you should use. There will be an algorithm design question for divide and conquer but it is not difficult. Problems are not necessarily sorted in level of difficulty.