Greedy Algorithm. Algorithm Fall Semester

Similar documents
Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

V = set of vertices (vertex / node) E = set of edges (v, w) (v, w in V)

10.2 Graph Terminology and Special Types of Graphs

MITSUBISHI ELECTRIC RESEARCH LABORATORIES Cambridge, Massachusetts. Introduction to Matroids and Applications. Srikumar Ramalingam

CS 241 Week 4 Tutorial Solutions

Lecture 8: Graph-theoretic problems (again)

Distance vector protocol

Graph theory Route problems

Lesson 4.4. Euler Circuits and Paths. Explore This

Outline. CS38 Introduction to Algorithms. Graphs. Graphs. Graphs. Graph traversals

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

Calculus Differentiation

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

The Greedy Method. The Greedy Method

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

1 Disjoint-set data structure.

Lexical Analysis: Constructing a Scanner from Regular Expressions

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence

2 Computing all Intersections of a Set of Segments Line Segment Intersection

Lecture 13: Graphs I: Breadth First Search

COMBINATORIAL PATTERN MATCHING

COMP 423 lecture 11 Jan. 28, 2008

COMMON FRACTIONS. or a / b = a b. , a is called the numerator, and b is called the denominator.

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem

Slides for Data Mining by I. H. Witten and E. Frank

What are suffix trees?

Minimal Memory Abstractions

Outline. Introduction Suffix Trees (ST) Building STs in linear time: Ukkonen s algorithm Applications of ST

Paradigm 5. Data Structure. Suffix trees. What is a suffix tree? Suffix tree. Simple applications. Simple applications. Algorithms

Introduction. Example

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

COMP108 Algorithmic Foundations

Ma/CS 6b Class 1: Graph Recap

1.5 Extrema and the Mean Value Theorem

CMPUT101 Introduction to Computing - Summer 2002

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

Ma/CS 6b Class 1: Graph Recap

Internet Routing. IP Packet Format. IP Fragmentation & Reassembly. Principles of Internet Routing. Computer Networks 9/29/2014.

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv

Definition of Regular Expression

Graphs with at most two trees in a forest building process

12/9/14. CS151 Fall 20124Lecture (almost there) 12/6. Graphs. Seven Bridges of Königsberg. Leonard Euler

WORKSHOP 9 HEX MESH USING SWEEP VECTOR

Suffix Tries. Slides adapted from the course by Ben Langmead

Graph Contraction and Connectivity

Information Retrieval and Organisation

Premaster Course Algorithms 1 Chapter 6: Shortest Paths. Christian Scheideler SS 2018

Fig.25: the Role of LEX

UTMC APPLICATION NOTE UT1553B BCRT TO INTERFACE PSEUDO-DUAL-PORT RAM ARCHITECTURE INTRODUCTION ARBITRATION DETAILS DESIGN SELECTIONS

Distributed Systems Principles and Paradigms

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

CS481: Bioinformatics Algorithms

Can Pythagoras Swim?

CS 551 Computer Graphics. Hidden Surface Elimination. Z-Buffering. Basic idea: Hidden Surface Removal

4452 Mathematical Modeling Lecture 4: Lagrange Multipliers

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

Final Exam Review F 06 M 236 Be sure to look over all of your tests, as well as over the activities you did in the activity book

CS553 Lecture Introduction to Data-flow Analysis 1

Intermediate Information Structures

Outline. Motivation Background ARCH. Experiment Additional usages for Input-Depth. Regular Expression Matching DPI over Compressed HTTP

Distributed Systems Principles and Paradigms. Chapter 11: Distributed File Systems

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

Typing with Weird Keyboards Notes

Internet Routing. Reminder: Routing. CPSC Network Programming

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Class Overview. Database Design. Database Design Process. Database Design. Introduction to Data Management CSE 414

Suffix trees, suffix arrays, BWT

3D convex hulls. Convex Hull in 3D. convex polyhedron. convex polyhedron. The problem: Given a set P of points in 3D, compute their convex hull

Advanced Programming Handout 5. Enter Okasaki. Persistent vs. Ephemeral. Functional Queues. Simple Example. Persistent vs.

Dr. D.M. Akbar Hussain

Error Numbers of the Standard Function Block

10.5 Graphing Quadratic Functions

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

ZZ - Advanced Math Review 2017

Lecture 12 : Topological Spaces

Presentation Martin Randers

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley

Section 2.3 Functions. Definition: Let A and B be sets. A function (mapping, map) f from A to B, denoted f :A B, is a subset of A B such that

Duality in linear interval equations

Greedy Algorithms Spanning Trees

Algorithm Design (5) Text Search

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

Outline. Graphs Describing Precedence. Graphs Describing Precedence. Topological SorFng of DAGs. Graphs Describing Precedence 4/25/12. Part 10.

Chapter 4 Fuzzy Graph and Relation

CS201 Discussion 10 DRAWTREE + TRIES

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. General Tree Search. Uniform Cost. Lecture 3: A* Search 9/4/2007

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

A distributed edit-compile workflow

P(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have

Uninformed Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 31 Jan 2012

Problem Final Exam Set 2 Solutions

5 ANGLES AND POLYGONS

Width and Bounding Box of Imprecise Points

Network Interconnection: Bridging CS 571 Fall Kenneth L. Calvert All rights reserved

Pattern Matching. Pattern Matching. Pattern Matching. Review of Regular Expressions

A dual of the rectangle-segmentation problem for binary matrices

ASTs, Regex, Parsing, and Pretty Printing

CSc 453 Compilers and Systems Software. 6 : Top-Down Parsing I

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search

Transcription:

Greey Algorithm Algorithm 0 Fll Semester

Optimiztion prolems An optimiztion prolem is one in whih you wnt to fin, not just solution, ut the est solution A greey lgorithm sometimes works well for optimiztion prolems A greey lgorithm works in phses. At eh phse: You tke the est you n get right now, without regr for future onsequenes You hope tht y hoosing lol optimum t eh step, you will en up t glol optimum /

Exmple: Counting money Suppose you wnt to ount out ertin mount of money, using the fewest possile ills n oins A greey lgorithm woul o this woul e: At eh step, tke the lrgest possile ill or oin tht oes not overshoot Exmple: To mke $.9, you n hoose: $5 ill $ ill, to mke $ 5 oin, to mke $.5 A 0 oin, to mke $.5 four oins, to mke $.9 For US money, the greey lgorithm lwys gives the optimum solution /

A filure of the greey lgorithm In some (fitionl) monetry system, krons ome in kron, 7 kron, n 0 kron oins Using greey lgorithm to ount out 5 krons, you woul get A 0 kron piee Five kron piees, for totl of 5 krons This requires six oins A etter solution woul e to use two 7 kron piees n one kron piee This only requires three oins The greey lgorithm results in solution, ut not in n optiml solution /

Exmple : Mking hnges 5 /

Huffmn oes Any inry tree with eges lele with 0 s n s yiels prefixfree oe of hrters ssigne to its leves Optiml inry tree minimizing the expete (weighte verge) length of oewor n e onstrute s follows Huffmn s lgorithm Initilize n one-noe trees with lphet hrters n the tree weights with their frequenies. Repet the following step n- times: join two inry trees with smllest weights into one (s left n right sutrees) n mke its weight equl the sum of the weights of the two trees. Mrk eges leing to left n right sutrees with 0 s n s, respetively. /

Huffmn enoing The Huffmn enoing lgorithm is greey lgorithm You lwys pik the two smllest numers to omine 00 5 7 5 7 9 A B C D E F A=00 B=00 C=0 D=00 E= F=0 7 /

0. 0.5 0. 0. 0.5 B _ C D A Exmple 0. C 0. D 0.5 0.5 A hrter A B C D _ 0. 0.5 frequeny 0.5 0. 0. 0. 0.5 B _ 0.5 0.5 A 0. 0. 0.5 0. 0. B _ C D oewor 00 00 0 0 0. 0. Enoe the text ADCB : 00000 0. C 0. D 0. B 0.5 0.5 _ 0.5 A.0 Deoe the text whose enoing is 000000000 : CDB_ACD 0 0. 0 0 0. 0. 0.5 C D 0 0. 0.5 A 0. B 0.5 _ 8 /

In-Clss Exerise Buil huffmn tree for the following: A x ={,,,, e } P x ={0.5, 0.5, 0., 0.5, 0.5} Define the oewor for eh lphet. Enoe the text - e 9 /

Minimum spnning tree A minimum spnning tree is lest-ost suset of the eges of grph tht onnets ll the noes Strt y piking ny noe n ing it to the tree Repetely: Pik ny lest-ost ege from noe in the tree to noe not in the tree, n the ege n new noe to the tree Stop when ll noes hve een e to the tree 5 The result is lest-ost (++++=) spnning tree If you think some other ege shoul e in the spnning tree: Try ing tht ege Note tht the ege is prt of yle To rek the yle, you must remove the ege with the gretest ost This will e the ege you just e 0 /

Trveling slesmn A slesmn must visit every ity (strting from ity A), n wnts to over the lest possile istne He n revisit ity (n reuse ro) if neessry He oes this y using greey lgorithm: He goes to the next nerest ity from wherever he is A B C D E From A he goes to B From B he goes to D This is not going to result in shortest pth! The est result he n get now will e ABDBCE, t ost of An tul lest-ost pth from A is ADBCE, t ost of /

Other greey lgorithms Dijkstr s lgorithm for fining the shortest pth in grph Alwys tkes the shortest ege onneting known noe to n unknown noe Prim s lgorithm for fining minimum-ost spnning tree Alwys tkes the lowest-ost ege etween noes in the spnning tree n noes not yet in the spnning tree Kruskl s lgorithm for fining minimum-ost spnning tree Alwys tries the lowest-ost remining ege /

Dijkstr : Exmple 7 5 e Tree verties (-,0) Remining verties (,) (-, ) (,7) e(-, ) 5 7 e (,) (,+) (,+) e(-, ) 5 7 e (,5) (,7) e(,5+) 5 7 e (,7) e(,9) e(,9) 5 7 e

In-Clss Exerise Apply Dijkstr s lgorithm to fin the shortest pth in the following grph. /

Kruskl s MST - Exmple 5 /

Prim s MST - Exmple /

In-Clss Exerise Fin minimum-ost spnning tree Kruskl Prim 7 /

Conneting wires There re n white ots n n lk ots, eqully spe, in line You wnt to onnet eh white ot with some one lk ot, with minimum totl length of wire Exmple: Totl wire length ove is + + + 5 = 8 Do you see greey lgorithm for oing this? Does the lgorithm gurntee n optiml solution? Cn you prove it? Cn you fin ounterexmple? 8 /

A sheuling prolem You hve to run nine jos, with running times of, 5,, 0,,, 5, 8, n 0 minutes You hve three proessors on whih you n run these jos You eie to o the longest-running jos first, on whtever proessor is ville P 0 0 P P 8 5 5 Time to ompletion: 8 + + = 5 minutes This solution isn t, ut we might e le to o etter 9 /

Another pproh Wht woul e the result if you rn the shortest jo first? Agin, the running times re, 5,, 0,,, 5, 8, n 0 minutes P 0 5 P P 5 8 0 Tht wsn t suh goo ie; time to ompletion is now + + 0 = 0 minutes Note, however, tht the greey lgorithm itself is fst All we h to o t eh stge ws pik the minimum or mximum 0 /

An optimum solution Better solutions o exist: P 0 P P 8 5 5 0 /

Tsk Sheuling Given: set T of n tsks, eh hving: A strt time, s i A finish time, f i (where s i < f i ) Gol: Perform ll the tsks using minimum numer of mhines. Mhine Mhine Mhine 5 7 8 9 /

Exmple Given: set T of n tsks, eh hving: A strt time, s i A finish time, f i (where s i < f i ) [,], [,], [,5], [,7], [,7], [,9], [7,8] (orere y strt) Gol: Perform ll tsks on min. numer of mhines /

Q & A