Algorithm Design - hni.uni-paderborn.de · Algorithms and Complexity Online Algorithms An online...

Preview:

Citation preview

Friedhelm Meyer auf der Heide 1

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Welcome to the course

Algorithm Design

Summer Term 2011

Friedhelm Meyer auf der Heide

Lecture 12, 8.7.2011

Friedhelm Meyer auf der Heide 2

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Randomised Algorithms

Friedhelm Meyer auf der Heide 3

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityTopics

- Divide & conquer

- Dynamic programming

- Greedy Algorithms

- Randomized Algorithms

- Approximation Algorithms

- Online Algorithms

Friedhelm Meyer auf der Heide 4

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityOnline Algorithms

An online algorithm is one that can process its input piece-by-piece,

without having the entire input available from the start.

In contrast, an offline algorithm is given the whole problem data from the

beginning and is required to output an answer which solves the problem

at hand.

Input: a sequence of requests.

Task: process the requests as efficiently as possible

Online:

i„th request has to be processed before future requests are known

Offline:

All requests are known in advance

Friedhelm Meyer auf der Heide 5

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityHow to measure quality of online algorithms?

1. Assume some a priori knowledge about request

sequence, e.g., „requests are chosen randomly“

2. Assume worst case measure, compare online cost to

offline cost

Online : standard competitive analysis – competitive ratio

Online randomized:

Friedhelm Meyer auf der Heide 6

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Paging

Friedhelm Meyer auf der Heide 7

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Paging:

A basic problem for an operating system

• Main memory

• Size k=6

• Disk

Paging: given a main memory that can

hold k pages.

Input: request sequence of pages to be

used by the processor

Goal: Need as few page faults ( requests

for pages that have to be moved from

disk to main memory)

The algorithm has to store the requested

page in main memory in case of a page

fault, and has to choose a page to be

removed from main memory.

Friedhelm Meyer auf der Heide 8

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityPaging

Optimal offline:

Friedhelm Meyer auf der Heide 9

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityPaging

Two online strategies:

Theorem: LRU and FIFO are k-competitive.

This competitive ratio is best possible.

Friedhelm Meyer auf der Heide 10

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityPaging

In practise, both algorithms are much better, the observed competitive ratio decreases with increasing memory size k.

Furthermore, LRU turns out to be better than FIFO.

Reasons: In practise, request sequences exhibit locality, i.e., they tend to use the same pages more often, and have dependencies among pages.

(„If page A is accessed, then it is likely that page B will be accessed shortly afterwards“)

Way out: Model restrictions to the „adversary“, i.e. the bad guy that generates the worst case sequences.

This is done using access graphs.

Friedhelm Meyer auf der Heide 11

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Page Migration

Friedhelm Meyer auf der Heide 12

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Page migration – Classical online problem

• processors connected by a network

There are costs of communication associated with each

edge. Cost of communication between pair of nodes =

cost of the cheapest path between these nodes.

• Costs of communication fulfill the triangle inequality.

Page Migration Model (1)

v1

v2

v3

v4

v7

v6

v5

Friedhelm Meyer auf der Heide 13

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Alternative view:

• processors in a metric space

Indivisible memory page of size in the local memory of

one processor (initially at )

Page Migration Model (2)

v1

v2

v3

v4

v7

v6

v5

Friedhelm Meyer auf der Heide 14

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityPage Migration Model (3)

Input: sequence of processors,

dictated by a request adversary

- processor which wants to access (read or write)

one unit of data from the memory page.

After serving a request an algorithm may move the page

to a new processor.

v1

v2

v3

v4

v7

v6

v5

Friedhelm Meyer auf der Heide 15

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityPage Migration (cost model)

Cost model:

The page is at node .

Serving a request issued at costs .

Moving the page to node costs .

Friedhelm Meyer auf der Heide 16

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityA randomized algorithm

Memoryless coin-flipping algorithm CF [Westbrook 92]

Theorem: CF is 3-competitive against an adaptive-online

adversary (may see the outcomes of the coinflips).

Remark: This ratio is optimal against adaptive-online

adversary.

In each step, after serving a request issued at ,

move page to with probability .

Friedhelm Meyer auf der Heide 17

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityProof of competitiveness of CF

We run CF and OPT „in parallel” on the input sequence

We define potential function

There are two events to consider in each step

– Request occurs at a node ,

– CF and OPT serve the requests, part 1

– CF optionally moves the page

– OPT optionally moves the page } part 2

– For each part separately, we prove that

Friedhelm Meyer auf der Heide 18

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityProof of competitiveness of CF

Note:

This is a telescopic sum.

Thus the cancel out

and we get the competitive ratio 3.

Friedhelm Meyer auf der Heide 19

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityCompetitiveness of CF, a step

Page in and resp.

Request occurs at

CF and OPT serve the requests

CF optionally moves the page to part 1

OPT optionally moves the page part 2

to

Friedhelm Meyer auf der Heide 20

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityCompetitiveness of CF – part 1

Request occurs at

Cost of serving requests:

in CF : a, in OPT : b

Expected cost of moving the page:

Potential before:

Exp. potential after:

Exp. change of the potential:

Friedhelm Meyer auf der Heide 21

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityCompetitiveness of CF – part 2

OPT moves to

Friedhelm Meyer auf der Heide 22

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityDeterministic algorithm

Algorithm Move-To-Min (MTM) [Awerbuch, Bartal, Fiat 93]

Theorem: MTM is 7-competitive

Remark: The currently best deterministic algorithm achieves

competitive ratio of 4.086

After each steps, choose to be the node

which minimizes , and move to .

( is the best place for the page in the last steps)

Friedhelm Meyer auf der Heide 23

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and ComplexityResults on page migration

The best known bounds:

Algorithm Lower bound

Deterministic

[Bartal, Charikar, Indyk

„96]

[Chrobak, Larmore,

Reingold, Westbrook „94]

Randomized:

Oblivious

adversary

[Westbrook „91] [Chrobak, Larmore,

Reingold, Westbrook „94]

Randomized:

Adaptive-online

adversary

[Westbrook „91] [Westbrook „91]

Friedhelm Meyer auf der Heide 24

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Data management in networks

Friedhelm Meyer auf der Heide 25

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Scenario

Networks have low bandwidth, global objects are small, access is

fine grained.

• typical for parallel processor networks, partially also for the internet.

• bottleneck: link-congestion

task: distribute global objects (maybe dynamically) among

processors such that

• an application (sequence of read/write access to global

variables) can be executed using small link-congestion

• storage overhead is small.

- Exploit Locality -

Friedhelm Meyer auf der Heide 26

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Basic Strategy

Design strategy for trees

Produce strategy for target-network by tree embedding

Friedhelm Meyer auf der Heide 27

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Dynamic Model

Application: Sequence of read / write requests from processors

to objects. Each processor decides solely based on

its local knowledge.

distributed online-strategy

Goal: Develop strategy that produces only by a factor c more

congestion than an optimal offline strategy.

c-competitive strategy

(and by a factor m more storage per processor

(m, c) – competitive strategy )

Friedhelm Meyer auf der Heide 28

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Dynamic strategy for trees

v writes to x :

v creates (or updates) copy of x in v,

and invalidates all other copies (consistency!)

v reads x:

v reads the closest copy of x and creates copies in

every processor on the path back to v.

(Remark: Data Tracking in trees is easy!)

Friedhelm Meyer auf der Heide 29

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

Friedhelm Meyer auf der Heide 30

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

Friedhelm Meyer auf der Heide 31

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

Friedhelm Meyer auf der Heide 32

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

v2

Friedhelm Meyer auf der Heide 33

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

v2

Friedhelm Meyer auf der Heide 34

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

v2

v3

Friedhelm Meyer auf der Heide 35

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

v2

v3

vk

Friedhelm Meyer auf der Heide 36

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Example and Analysis

Consider phase write (v0), read (v1), read (v2), ... , read (vk-1), write (vk)

v0

v1

v2

v3

Each strategy has to use each link of the red subtree at least once.

Our strategy uses each of these links at most three times.

Strategy is 3-competitive for trees

vk

Friedhelm Meyer auf der Heide 37

HEINZ NIXDORF INSTITUTE

University of Paderborn

Algorithms and Complexity

Friedhelm Meyer auf der Heide

Heinz Nixdorf Institute

& Computer Science Department

University of Paderborn

Fürstenallee 11

33102 Paderborn, Germany

Tel.: +49 (0) 52 51/60 64 80

Fax: +49 (0) 52 51/62 64 82

E-Mail: fmadh@upb.de

http://www.upb.de/cs/ag-madh

Thank you for

your attention!

Recommended