Instructor: Shengyu Zhang 1. Content Two problems  Minimum Spanning Tree  Huffman encoding One approach: greedy algorithms 2.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Repaso: Unidad 1 Lección 2
Mathematical Preliminaries
Unit-iv.
AP STUDY SESSION 2.
1
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
UNITED NATIONS Shipment Details Report – January 2006.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Create an Application Title 1A - Adult Chapter 3.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Break Time Remaining 10:00.
Turing Machines.
PP Test Review Sections 6-1 to 6-6
EU market situation for eggs and poultry Management Committee 20 October 2011.
Bright Futures Guidelines Priorities and Screening Tables
Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
2 |SharePoint Saturday New York City
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
Factors, Prime Numbers & Composite Numbers
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
1 On c-Vertex Ranking of Graphs Yung-Ling Lai & Yi-Ming Chen National Chiayi University Taiwan.
Note to the teacher: Was 28. A. to B. you C. said D. on Note to the teacher: Make this slide correct answer be C and sound to be “said”. to said you on.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
CSE Lecture 17 – Balanced trees
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
The Pumping Lemma for CFL’s
Presentation transcript:

Instructor: Shengyu Zhang 1

Content Two problems  Minimum Spanning Tree  Huffman encoding One approach: greedy algorithms 2

Example 1: Minimum Spanning Tree 3

MST: Problem and Motivation

More precisely

MST: The abstract problem

Methodology 4: Starting from a naïve solution  See whether it works well enough  If not, try to improve it. A first attempt may not be correct But that’s fine. The key is that it’ll give you a chance to understand the problem. 7

What if I’m really stingy? I’ll first pick the cheapest edge. I’ll then again pick the cheapest one in the remaining edges I’ll just keep doing like this …  as long as no cycle caused … until a cycle is unavoidable. Then I’ve got a spanning tree!  No cycle.  Connected: Otherwise I can still pick something without causing a cycle. Concern: Is there a better spanning tree?

Kruskal's Algorithm What we did just now is Kruskal’s algorithm.  Repeatedly add the next lightest edge that doesn't produce a cycle… in case of a tie, break it arbitrarily.  …until finally reaching a tree --- that’s the answer! 9

Illustrate an execution of the algorithm At first all vertices are all separated. Little by little, they merge into groups. Groups merge into larger groups. Finally, all groups merge into one. That’s the spanning tree outputted by the algorithm

Correctness: prove by induction 11

Correctness: prove by induction 12 5

Implementing Kruskal's Algorithm: 13

Implementation 14

Data structure 15

Kruskal's Algorithm: rewritten, complexity 16

data structure for union-find 17

union Recall: a tree is constructed by a sequence of union operations. So we want to design a union algorithm s.t.  the resulting tree is short  the cost of union itself is not large either. A natural idea: let the shorter tree be part of the higher tree  Actually right under the root of the higher tree To this end, we need to maintain the height information of a tree, which is pretty easy. 18

19

How good is this? 20

Cost of union? 21

Don’t confuse the two types of trees Type 1: (parts of) the spanning tree  Red edges Type 2: the tree data structure used for implementing union-find operations  Blue edges

Question? Next: another MST algorithm. 23

Next: another MST algorithm 24

Execution on the same example v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 v9v9 25

Key property v1v1 v2v2 v3v3 v4v4 v5v5 26

Prim’s algorithm 28

Extra: Divide and Conquer?

Example 2: Huffman code 30

Huffman encoding 31

Example 32

Requirement for the code 33

Prefix-free code and binary tree A B C D Path: represented by sequence of 0’s and 1’s. 0: left branch. 1: right branch 34

Optimal tree? 35

In an optimal tree 36

Algorithm, formal description 37

On the running example… A:20 B:10 C:5 D:

Summary We give two examples for greedy algorithms.  MST, Huffman code General idea: Make choice which is the best at the moment only.  without worrying about long-term consequences. An intriguing question: When greedy algorithms work?  Namely, when there is no need to think ahead? Matroid theory provides one explanation.  See CLRS book (Chapter 16.4) for a gentle intro. 39