Greedy Algorithms. Activity-selection problem. Optimization Problem. Example

Similar documents
Efficient Sequential Algorithms, Comp309. Problems. Part 1: Algorithmic Paradigms

Approximation Basics

Cost Functions in Machine Learning

Greedy algorithms is another useful way for solving optimization problems.

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Greedy Algorithms CLRS Laura Toma, csci2200, Bowdoin College

Greedy Algorithms. T. M. Murali. January 28, Interval Scheduling Interval Partitioning Minimising Lateness

CSE 421 Applications of DFS(?) Topological sort

Framework for Design of Dynamic Programming Algorithms

Theorem 2.9: nearest addition algorithm

2SAT Andreas Klappenecker

Approximation Algorithms

15.4 Longest common subsequence

Algorithms Dr. Haim Levkowitz

Minimum Spanning Tree

Subset sum problem and dynamic programming

Dist(Vertex u, Vertex v, Graph preprocessed) return u.dist v.dist

Dual-fitting analysis of Greedy for Set Cover

Greedy Approximations

Natasha S. Sharma, PhD

Chapter 16. Greedy Algorithms

Algorithm Design and Analysis

Bulldozers/Sites A B C D

Cantor s Diagonal Argument for Different Levels of Infinity

NP and computational intractability. Kleinberg and Tardos, chapter 8

Traveling Salesman Problem (TSP) Input: undirected graph G=(V,E), c: E R + Goal: find a tour (Hamiltonian cycle) of minimum cost

Algorithm Analysis. Applied Algorithmics COMP526. Algorithm Analysis. Algorithm Analysis via experiments

1 Linear programming relaxation

16 Greedy Algorithms

Storage Allocation Based on Client Preferences

The Join the Club Interpretation of Some. Graph Algorithms

COUNTING THE NUMBER OF WINNING BINARY STRINGS IN THE 1-DIMENSIONAL SAME GAME. Department of Mathematics Oberlin College Oberlin OH 44074

Greedy Algorithms CSE 780

Elements of Dynamic Programming. COSC 3101A - Design and Analysis of Algorithms 8. Discovering Optimal Substructure. Optimal Substructure - Examples

Algorithm Design Methods. Some Methods Not Covered

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #19. Loops: Continue Statement Example

6.856 Randomized Algorithms

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility

c. Show that each unit fraction, with, can be written as a sum of two or more different unit fractions.

Optimisation While Streaming

Heuristic Optimisation

Text Compression through Huffman Coding. Terminology

A Randomized Algorithm for Minimizing User Disturbance Due to Changes in Cellular Technology

arxiv: v2 [cs.dm] 3 Dec 2014

tree follows. Game Trees

REDUCING GRAPH COLORING TO CLIQUE SEARCH

Algorithm and Complexity of Disjointed Connected Dominating Set Problem on Trees

COMP251: Greedy algorithms

Approximation Algorithms

Zero-Knowledge Proofs. Zero-Knowledge Proofs. Slides from a Talk by Eric Postpischil

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Approximation Algorithms

Chapter 23. Minimum Spanning Trees

10. EXTENDING TRACTABILITY

10. EXTENDING TRACTABILITY

CMPUT 396 Sliding Tile Puzzle

Lecture 9 & 10: Local Search Algorithm for k-median Problem (contd.), k-means Problem. 5.1 Local Search Algorithm for k-median Problem

18 Spanning Tree Algorithms

5 MST and Greedy Algorithms

Vertex Cover Approximations

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

Greedy Algorithms CSE 6331

val(y, I) α (9.0.2) α (9.0.3)

CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh HW#3 Due at the beginning of class Thursday 02/26/15

31.6 Powers of an element

1 Better Approximation of the Traveling Salesman

College of Computer & Information Science Fall 2007 Northeastern University 14 September 2007

5 MST and Greedy Algorithms

Lecture 7: Asymmetric K-Center

6. Dicretization methods 6.1 The purpose of discretization

CS 137 Part 7. Big-Oh Notation, Linear Searching and Basic Sorting Algorithms. November 10th, 2017

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.

Section 4: Extreme Values & Lagrange Multipliers.

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

1 Definition of Reduction

Hashing for searching

We augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real

Partha Sarathi Mandal

Quick Guide. Managing Existing Projects

16.Greedy algorithms

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

Algorithms: COMP3121/3821/9101/9801

Order Analysis of Algorithms. Sorting problem

Column Generation Method for an Agent Scheduling Problem

Optimization of fuzzy multi-company workers assignment problem with penalty using genetic algorithm

COMPUTER SCIENCE TRIPOS

The problem of minimizing the elimination tree height for general graphs is N P-hard. However, there exist classes of graphs for which the problem can

Greedy Algorithms CHAPTER 16

Outline of the module

Bipartite Graph Partitioning and Content-based Image Clustering

Constructive and destructive algorithms

The Maximum Facility Location Problem

Data Clustering. Danushka Bollegala

On the Max Coloring Problem

Cardinality of Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Cardinality of Sets Fall / 15

Solutions for the Exam 6 January 2014

Non-deterministic Search techniques. Emma Hart

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Greedy Algorithms. Informal Definition A greedy algorithm makes its next step based only on the current state and simple calculations on the input.

Exam problems for the course Combinatorial Optimization I (DM208)

Transcription:

Greedy Algorithms We consider optimisation problems. Algorithms for optimization problems typically go through a sequence of steps, with a set of choices at each step. A greedy algorithm is a process that always makes the choice that looks best at the moment. Greedy algorithms are natural, and in few cases solve optimally the given problem. We will look at one simple example and we will try to understand why does it work. We will consider more examples later. Activity-selection problem We are given a set of proposed activities S = {A 1, A 2,...,A n } that wish to use a resource, which can be used by only one activity at a time. Each activity is defined by a pair consisting of a start time s i and a finish time f i, with 0 s i < f i < +. If selected, activity A i takes place during the time interval [s i, f i ). Two activities A i and A j are compatible if s i f j or s j f i. The activity-selection problem is to select the maximum number of mutually compatible activities. 1 3 Optimization Problem An optimisation problem P is defined by four components (I, SOL, c, opt) where: (1) I is the set of the instances of P. Membership in I is decidable in polynomial time. (2) For each x I, SOL(x) is the set of solutions of x. Membership in SOL(x) is decidable in polynomial time and for each y SOL(x), the length of y is polynomial in the length of x. (3) For each x I and each y SOL(x), c(x, y) is an integer, non-negative function, called the objective (or cost) function. (4) opt {max, min} is the optimisation criterion and tells if the problem P is a maximisation or a minimisation problem. Example 2 4

Open issues How far can we go? Scale this up to a real life situation, where there may be few hundreds activities. We write some software that, when run on a particular example, returns 50 activities: is this the best?? The people who employ us may wonder whether it is possible to do better? Unprofessional answer: Yep! Better answer: My program is certified to produce the best possible answer (I can show you the program AND a mathematical proof that it works)! 4-1 6 Two possible solutions (the columns marked by a * correspond to activities picked in the particular solution). * * * * * Example of Real Life Application Time-dependent web browsing The access speeds to particular sites on the World Wide Web can vary depending on the time of access. Figure 1: Access rates for USA and Asia over 24 hours. (Derived from data posted by the Anderson News Network http://www.internettrafficreport.com/) 5 7

A single central computer (e.g. a search engine server) collects all the information stored in a certain number of web documents, located at various sites. The information is gathered by scheduling a number of consecutive client/server TCP connections with the required web sites. We assume that the loading time of any particular page from any site may be different at different times, e.g. the access to the page is much slower in peak hours than in off-peak hours. Having a list of pages to be collected along with some information about the access time at any given instant, the goal is to download as many pages as possible. It is an optimisation problem. The set of instances coincides with the set of all possible groups of activities (in tabular form). A solution is a set of compatible activities. The cost of a solution is its size (or cardinality), and we are seeking a maximum cardinality solution. How do we solve it? What is a good strategy? 8 10 Typical input for this problem can be a sequence of tables like the following (times are GMT), one for each remote web site www.one.com t1 0.00 0.15 t2 0.30 0.47 t3 1.00 1.35 t4 1.30 2.06 t24 11.30 12.29 t25 12.00 13.13 Greedy algorithm GREEDY-ACTIVITY-SELECTOR (S, n) j index of the minimum f i in S X {A j } S S \ {A j } for i 2 to n k index of the minimum f i in S if s k f j X X {A k } j k S S \ {A k } return X 9 11

Remarks. The algorithm takes as input a set of activities S (each activity stored as a pair of numbers (s i, f i )) and the total number of activities n. The set X collects the selected activities. The variable j always specifies the most recent addition to X. Notice also that the pseudo-code is using sets but any implementation of GREEDY-ACTIVITY-SELECTOR will have to use arrays, vectors or some other data structure present in the chosen programming language. Time complexity Claim. The time complexity of GREEDY-ACTIVITY-SELECTOR is O(n 2 ) (assuming that set update operations only cost one step each!). Each iteration of the for loop lasts for at most S + 3 steps. The size of S decreases by one at each iterations (initially S = n). The total number of steps is therefore (n + 2) + ((n 1) + 3) + ((n 2) + 3) +... + (1 + 3) }{{} n times which is at most n ((n + 3) + 3) = n 2 + 6n (or, exactly, n 2 +7n 2 1, if we a just a bit more careful with the arithmetic). 12 14 Examples (1) Back to the first example we considered. The run time can be reduced to O(n log n) by an algorithm that combines a linear time greedy heuristic with a sort preprocessing step. What are the algorithm choices? Let s simulate it! (2) Time-dependent web browsing site 1 2 3 4 5 6 7 8 9 10 11 12 s i 9.15 7.42 10.00 11.54 9.17 9.47 7.34 8.16 8.36 10.45 11.53 11.05 f i 9.35 7.49 11.34 12.52 9.57 10.19 8.51 9.23 9.25 10.56 12.30 12.16 Problem? You are not guaranteed to get information from all of them. This requirement can make the problem quite difficult (more later). SGREEDY-ACTIVITY-SELECTOR (S, n) sort S in order of increasing finishing time j 1 X {A j } for i 2 to n if s i f j X X {A i } j i return X 13 15

Here is the same example, after the execution of the first step of SGREEDY-ACTIVITY-SELECTOR. i 9 2 12 6 7 11 5 8 1 4 10 3 s i 16 7 26 49 44 27 27 44 44 83 58 37 f i 17 25 57 62 70 79 84 84 86 89 94 96 The algorithm eventually selects activities 9, 12, and 4. 16