CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Similar documents
GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

COMP108 Algorithmic Foundations

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

CS 461, Lecture 17. Today s Outline. Example Run

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

CS 241 Analysis of Algorithms

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

CSI35 Chapter 11 Review

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Planar Upward Drawings

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

Section 10.4 Connectivity (up to paths and isomorphism, not including)

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

12. Traffic engineering

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Compression. Compression. Compression. This part of the course... Ifi, UiO Norsk Regnesentral Vårsemester 2005 Wolfgang Leister

QUESTIONS BEGIN HERE!

0.1. Exercise 1: the distances between four points in a graph

Minimum Spanning Trees

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

Garnir Polynomial and their Properties

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

(a) v 1. v a. v i. v s. (b)

EE1000 Project 4 Digital Volt Meter

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

Problem solving by search

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Constructive Geometric Constraint Solving

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

Lecture 20: Minimum Spanning Trees (CLRS 23)

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

LEO VAN IERSEL TU DELFT

Nefertiti. Echoes of. Regal components evoke visions of the past MULTIPLE STITCHES. designed by Helena Tang-Lim

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Graph Contraction and Connectivity

Chapter 9. Graphs. 9.1 Graphs

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

1 Introduction to Modulo 7 Arithmetic

Preview. Graph. Graph. Graph. Graph Representation. Graph Representation 12/3/2018. Graph Graph Representation Graph Search Algorithms

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Construction 11: Book I, Proposition 42

Last time: introduced our first computational model the DFA.

Scientific Programming. Graphs

Computational Biology, Phylogenetic Trees. Consensus methods

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

XML and Databases. Outline. Recall: Top-Down Evaluation of Simple Paths. Recall: Top-Down Evaluation of Simple Paths. Sebastian Maneth NICTA and UNSW

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

(Minimum) Spanning Trees

Constructing Minimal Spanning/Steiner Trees. with Bounded Path Length. Department of EE-Systems

QUESTIONS BEGIN HERE!

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

Outline. Binary Tree

Section 3: Antiderivatives of Formulas

Analysis for Balloon Modeling Structure based on Graph Theory

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Decimals DECIMALS.

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

Numbering Boundary Nodes

A 4-state solution to the Firing Squad Synchronization Problem based on hybrid rule 60 and 102 cellular automata

IEEE TRANSACTIONS ON COMPUTATIONAL BIOLOGY AND BIOINFORMATICS, VOL. TK, NO. TK, MONTHTK YEARTK 1. Hamiltonian Walks of Phylogenetic Treespaces

Seven-Segment Display Driver

Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling

Present state Next state Q + M N

Clustering for Processing Rate Optimization

CS September 2018

CS553 Lecture Register Allocation I 3

CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Transcription:

CSC 801- Dsign n Anlysis of Algorithms Ltur 11 Gry Thniqu Exmpl: Chng-Mking Prolm Givn unlimit mounts of oins of nomintions 1 > > m, giv hng for mount n with th lst numr of oins Exmpl: 1 = 25, 2 =10, = 1 Gry solution for n = 8: Gry solution for n = 0: 2 1

Gry Thniqu Construts solution to n optimiztion prolm pi y pi through squn of hois tht r: fsil (stisfis th prolm s onstrints) lolly optiml (st hoi in h stp) irrvol ( hoi n t hng in susqunt stps) For som prolms, yils n optiml solution for vry instn. For most, it os not, ut n usful for fst pproximtions. Applitions of th Gry Strtgy Optiml solutions: hng mking for norml oin nomintions minimum spnning tr (MST) singl-sour shortst pths simpl shuling prolms Huffmn os Approximtions: trvling slsmn prolm (TSP) knpsk prolm othr omintoril optimiztion prolms 5 2

Minimum Spnning Tr (MST) Spnning tr of onnt grph G: onnt yli sugrph of G tht inlus ll of G s vrtis Minimum spnning tr of wight, onnt grph G: spnning tr of G of minimum totl wight Exmpl: 2 1 Prim s MST lgorithm Strt with tr T 1 onsisting of on (ny) vrtx n grow tr on vrtx t tim to prou MST through sris of xpning sutrs T 1, T 2,, T n On h itrtion, onstrut T i+1 from T i y ing vrtx not in T i tht is losst to thos lry in T i (this is gry stp!) Stop whn ll vrtis r inlu 7

Tring Prim s MST lgorithm 2 1 5 8 Prim s Implmnttion: Priority Quu Tr vrtis (-,-) Rmining vrtis (,2) (,) (-, ) (-, ) 2 1 5 nrst tr vrtx g wight 9

Nots out Prim s lgorithm Proof y inution tht this onstrution tully yils MST Ns priority quu for loting losst fring vrtx Effiiny O(n 2 ) for wight mtrix rprsnttion of grph n rry implmnttion of priority quu O(m log n) for jny list rprsnttion of grph with n vrtis n m gs n min-hp implmnttion of priority quu 10 Anothr gry lgorithm for MST: Kruskl s Sort th gs in nonrsing orr of lngths Grow tr on g t tim to prou MST through sris of xpning forsts F 1, F 2,, F n-1 On h itrtion, th nxt g on th sort list unlss this woul rt yl. (If it woul, skip th g.) 11 5

Kruskl s Implmnttion Tr gs Sort list of gs 5 2 1 12 Nots out Kruskl s lgorithm Algorithm looks sir thn Prim s ut is hrr to implmnt (hking for yls!) Cyl hking: yl is rt iff g onnts vrtis in th sm onnt omponnt Union-fin lgorithms s stion 9.2 Effiiny: O(m log m) for grph with m gs 1

Minimum spnning tr vs. Stinr tr 1 1 1 vs 1 1 Applition of Gry Strtgy Singl-Sour Shortst Pths 7

Exmpls Sour = 5 2 1 Sour = 5 2 1 1 Shortst pths Dijkstr s lgorithm Singl Sour Shortst Pths Prolm: Givn wight onnt grph G, fin shortst pths from sour vrtx s to h of th othr vrtis Dijkstr s lgorithm: Similr to Prim s MST lgorithm, with iffrnt wy of omputing numril lls: Among vrtis not lry in th tr, it fins vrtx u with th smllst sum v + w(v,u) whr v is vrtx for whih shortst pth hs n lry foun on pring itrtions (suh vrtis form tr) v is th lngth of th shortst pth form sour to v w(v,u) is th lngth (wight) of g from v to u 17 8

Dijkstr s Algorithm 7 2 5 Tr vrtis (-,0) Rmining vrtis prnt istn to root 18 Dijkstr s Algorithm 7 2 5 Tr vrtis Rmining vrtis (-,0) (,) (-, ) (,7) (-, ) (,) (,+) (,+2) (-, ) (,5) (,7) (,5+) 2 5 7 2 5 7 2 5 7 (,7) (,9) 2 5 7 (,9) 9

20 Nots on Dijkstr s lgorithm Dosn t work for grphs with ngtiv wights Applil to oth unirt n irt grphs Effiiny sm s Prim s: O( V 2 ) for grphs rprsnt y wight mtrix n rry implmnttion of priority quu O( E log V ) for grphs rprsnt y j. lists n min-hp implmnttion of priority quu Don t mix up Dijkstr s lgorithm with Prim s lgorithm! 21 10

Summry 22 Applition of Gry Strtgy Huffmn Trs n Cos 11

Prfix-Fr Cos Coing: ssignmnt of it strings to lpht hrtrs Cowors: it strings ssign for hrtrs of lpht Two typs of os: fix-lngth noing (.g., ASCII) vril-lngth noing xmpl: Symol... Aritrry o Prfix-fr o Prfix-fr os: no owor is prfix of nothr owor 2 Coing Prolm Try this: using prfix-fr os, no th txt Coing Prolm: If frqunis of th hrtr ourrns r known, wht is th st inry prfix-fr o? 25 12

Huffmn os Any inry tr with gs ll with 0 s n 1 s yils prfix-fr o of hrtrs ssign to its lvs Optiml inry tr minimizing th xpt (wight vrg) lngth of owor n onstrut s follows Huffmn s lgorithm Initiliz n on-no trs with lpht hrtrs n th tr wights with thir frqunis. Rpt th following stp n-1 tims: join two inry trs with smllst wights into on (s lft n right sutrs) n mk its wight qul th sum of th wights of th two trs. Mrk gs ling to lft n right sutrs with 0 s n 1 s, rsptivly. 2 Exmpl hrtr A B C D _ frquny 0.5 0.1 0.15 27 1

Exmpl hrtr A B C D _ frquny 0.5 0.1 0.15 0.1 B 0.15 _ C D 0.5 A owor 11 100 00 01 101 C D 5 0.5 A vrg its pr hrtr: 2*0.5+*0.1+2*+2*+*0.15 = 2.25 for fix-lngth noing: omprssion rtio: (-2.25)/*100% = 25% 0.1 B 5 0.15 _ 0.1 B 0.5 A 0.15 _ C 0. D 1.0 0. 0. 0 1 0. 0 1 0 5 C D 0 1 0. 1 0.5 A C D 5 0.1 0.15 B _ 0.5 A 0.1 B 0.15 _ 28 Homwork Ring: Chptr 9 Exriss 9.1:, 5, 9 9.2: 1,, 5, 11 9.: 2,, 7 9.: 1, 29 1