1 Algorithms & Data Structures for Games Lecture 2A Minor Games Programming.

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

Greedy Algorithms.
Introduction to Algorithms Greedy Algorithms
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Algorithm Design Techniques: Greedy Algorithms. Introduction Algorithm Design Techniques –Design of algorithms –Algorithms commonly used to solve problems.
Greedy Algorithms Amihood Amir Bar-Ilan University.
Greedy Algorithms Basic idea Connection to dynamic programming
SIMS-201 Compressing Information. 2  Overview Chapter 7: Compression Introduction Entropy Huffman coding Universal coding.
Huffman Encoding Dr. Bernard Chen Ph.D. University of Central Arkansas.
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
For Monday Read 10.3 Homework: –Chapter 10, exercise 10.
1 Algorithms & Data Structures for games Lecture 2B Minor Games Programming.
Compression & Huffman Codes
1 Huffman Codes. 2 Introduction Huffman codes are a very effective technique for compressing data; savings of 20% to 90% are typical, depending on the.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
A Data Compression Algorithm: Huffman Compression
Compression & Huffman Codes Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 9 Greedy Technique Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
Greedy Algorithms CSE 331 Section 2 James Daly. Reminders Exam 2 next week Thursday, April 9th Covers heaps to spanning trees Greedy algorithms (today)
EEE377 Lecture Notes1 EEE436 DIGITAL COMMUNICATION Coding En. Mohd Nazri Mahmud MPhil (Cambridge, UK) BEng (Essex, UK) Room 2.14.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Data Compression Basics & Huffman Coding
Data Compression Gabriel Laden CS146 – Dr. Sin-Min Lee Spring 2004.
Huffman Codes Message consisting of five characters: a, b, c, d,e
Lecture 23. Greedy Algorithms
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
Data Compression1 File Compression Huffman Tries ABRACADABRA
Lossless Compression CIS 465 Multimedia. Compression Compression: the process of coding that will effectively reduce the total number of bits needed to.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Trees (Ch. 9.2) Longin Jan Latecki Temple University based on slides by Simon Langley and Shang-Hua Teng.
For Wednesday No reading No homework There will be homework for Friday, as well the program being due – plan ahead.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 9 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Trees (Ch. 9.2) Longin Jan Latecki Temple University based on slides by Simon Langley and Shang-Hua Teng.
1 Algorithms CSCI 235, Fall 2015 Lecture 30 More Greedy Algorithms.
Lecture 12 Huffman Algorithm. In computer science and information theory, a Huffman code is a particular type of optimal prefix code that is commonly.
1 Chapter 16: Greedy Algorithm. 2 About this lecture Introduce Greedy Algorithm Look at some problems solvable by Greedy Algorithm.
Greedy Algorithms Analysis of Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)
Greedy Algorithms.
Design & Analysis of Algorithm Huffman Coding
HUFFMAN CODES.
Greedy Technique.
Greedy function greedy { S <- S0 //Initialization
The Greedy Method and Text Compression
Greedy Algorithms Basic idea Connection to dynamic programming
Data Compression If you’ve ever sent a large file to a friend, you may have compressed it into a zip archive like the one on this slide before doing so.
Chapter 16: Greedy Algorithm
Chapter 16: Greedy Algorithms
Richard Anderson Autumn 2015 Lecture 8 – Greedy Algorithms II
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Algorithms (2IL15) – Lecture 2
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Data Structure and Algorithms
Greedy Algorithms Alexandra Stefan.
Richard Anderson Lecture 7 Greedy Algorithms
Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II
Lecture 2: Greedy Algorithms
Richard Anderson Autumn 2015 Lecture 7
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Analysis of Algorithms CS 477/677
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
Presentation transcript:

1 Algorithms & Data Structures for Games Lecture 2A Minor Games Programming

2 Algorithms and Data Structures  Feedback previous lectures  Theory: Greedy Algorithms Jan Verhoeven

3 Theory: Greedy Algorithms  Algorithm Design Techniques  10.1 Greedy Algorithms  A Simple Scheduling Problem  Hufman Codes  Approximate Bin Packing  Finally: some exercises

4 Greedy Algorithms  Definition: An algorithm that always takes the best immediate, or local, solution while finding an answer.  Greedy algorithms find the overall, or globally, optimal solution for some optimization problems, but may find less-than-optimal solutions for some instances of other problems. 

Coin-changing problem  How to minimize the number of bills and coins, when paying an amount in US currency Solution:  Greedy algorithm: repeatedly dispense the largest denomination. 5

6 Example

7  Okay, the algorithm usually works. In fact, for the U.S. coin system {1, 5, 10, 25}, it always yields the optimal set. However, for other sets, like {1, 5, 8, 10} and a goal of 13, this greedy algorithm would take one 10, and then three 1's, for a total of four coins, when the two coin solution {5, 8} also exists.

A small exercise  I buy a hamburger in Amsterdam and I pay in coins the amount of 3.98 euro’s.  What is the minimal numbers of coins I need to pay for the burger?  And when I buy 100 burgers?  The euro coins are 1, 2, 5, 10, 20, 50, 100 and 250 cents. 8

9 Problem: A Simple Scheduling Problem  What is the best way to schedule jobs in order to minimize the average completion time?  Greedy Solution: arrange by shortest job first

10 Possible schedules (single processor) Average completion time:Top: 25, Bottom: 17,75 (optimal) Optimal Schedule: arranged by shortest job first.

11 Multiprocessor case

12 Possible Schedules (3 processors) case I

13 Possible Schedules (3 processors) case II

14 Minimizing the final completion time (much harder to solve …)

A small exercise  How do I schedule on my 2 processor computer the following jobs and get the lowest possible average completion time?  J1(5), J2(2), J3(8), J4(1), J5(6), J6(4) with the restriction J4 can only run when J2 has been finished.  What is the average completion time? 15

16 Huffman Codes  File compression strategy: Allow the code length to vary from character to character and ensure that the frequently occurring characters have short codes.

17 Using a standard coding scheme

Representation of the original code in a tree 18

19 Optimal prefix code

20 Optimal prefix code: TREE

A small exercise  Please decode the following (hexadecimal) bit string in normal characters, using the optimal prefix code tree of previous slide: 1E06 D

22 Huffman’s Algorithm  Greedy,  To produce the optimal prefix code  See example in figure’s thru 10.19

A small exercise  Construct the Huffman code of the following text:  COFFEE TIME FOR YOU!!!!!!!!!!  What is the compression rate? 23

24 Approximate Bin Packing  We are given N items of sizes s 1, s 2,.., s n. The problem is to pack these items in the fewest number of bins.

25 Approximate Bin Packing  Greedy algorithms to solve the bin packing problem.  On-line bin packing:  Next fit  First fit  Best fit  Off-line bin packing:  First fit decreasing  Best fit decreasing

On-line and Off-line  On-line:  Each item must be placed in a bin before the next item can be processed.  Off-line:  We do not need to do anything until all the input has been read. 26

Next fit for 0.2, 0.5, 0.4, 0.7, 0.1, 0.3,

First fit for 0.2, 0.5, 0.4, 0.7, 0.1, 0.3,

Best fit for 0.2, 0.5, 0.4, 0.7, 0.1, 0.3,

Off-line  First sort the items in decreasing order.  Then execute first-fit or best-fit 30

31 Optimal packing for: 0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8

32 A small exercise Show the results of all the bin-packing strategies on the input: 0.1, 0.3, 0.5, 0.2, 0.8, 0.4, 0.7

33 Homework  Homework  Chapter 10.1  Exercises (should not be handed in!)  10.3  10.7 (program)  10.10