42
1 Planar point location -- example

Planar point location -- example

  • Upload
    elam

  • View
    51

  • Download
    0

Embed Size (px)

DESCRIPTION

Planar point location -- example. Planar point location & persistence (cont). Updates should be persistent since we need all search trees at the end. Partial persistence is enough. Well, we already have the path copying method, lets use it. What do we get ?. - PowerPoint PPT Presentation

Citation preview

Page 1: Planar point location -- example

1

Planar point location -- example

Page 2: Planar point location -- example

2

Planar point location & persistence (cont)

Updates should be persistent since we need all search trees at the end.

Partial persistence is enough

Well, we already have the path copying method, lets use it.What do we get ?

O(nlogn) space and O(nlog n) preprocessing time.

We shall improve the space bound to O(n).

Page 3: Planar point location -- example

3

What are we after ?

Break each operation into elementary access steps (ptr traversal) and update steps (assignments, allocations).

Want a persistent simulation with consumes O(1) time per update or access step, and O(1) space per update step.

Page 4: Planar point location -- example

4

Making data structures persistent (DSST 89)

We will show a general technique to make data structures partially and later fully persistent.

The time penalty of the transformation would be O(1) per elementary access and update step.

In particular, this would give us an O(n) space solution to the planar point location problem

The space penalty of the transformation would be O(1) per update step.

Page 5: Planar point location -- example

5

The fat node method

Every pointer field can store many values, each tagged with a version number.

5

7

15

NULL 4

Page 6: Planar point location -- example

6

The fat node method (Cont.)

5

7

15

NULL 4Simulation of an update step when producing version i:

• When a new node is created by the ephemeral update we create a new node, each value of a field in the new node is marked with version i.

• When we change a value of a field f to v, we add an entry to the list of f with key i and value v

Page 7: Planar point location -- example

7

The fat node method (Cont.)

5

7

15

NULL 4Simulation of an access step when navigating in version i:

• The relevant value is the one tagged with the largest version number smaller than i

Page 8: Planar point location -- example

8

Partialy persistent deques via the fat node method

V1x NullNull11

V2 = inject(y,V1)xNull21

y

Null1

2

Null2

Null

Null

V3 = eject(V2)xNull21

y

1

2

Null2

3

z

V4= inject(z,V3)xNull21

y

Null1

2

Null2

Null3

Null4

4 4

Page 9: Planar point location -- example

9

Fat node -- analysis

Space is ok -- O(1) per update step

That would give O(n) space for planar point location since each insertion/deletion does O(1) changes amortized.

We screwed up the update time, it may take O(log m) to traverse a pointer, where m is the # of versions

So query time goes up to O(log2n) and preprocessing time is O(nlog2n)

Page 10: Planar point location -- example

10

Node copying

This is a general method to make pointer based data structures partially persistent.

Idea: It is similar to the fat node method just that we won’t make nodes too fat.

We will show this method first for balanced search trees which is a slightly simpler case than the general case.

Nodes have to have bounded in degree and bounded outdegree

Page 11: Planar point location -- example

11

Partially persistent balanced search trees via node copying

Here it suffices to allow one extra pointer field in each node

When the ephemeral update changes a pointer field if the extra pointer is empty use it, otherwise copy the node. Try to store pointer to the new copy in its parent.

If the extra ptr at the parent is occupied copy the parent and continue going up this way.

Each extra pointer is tagged with a version number and a field name.

When the ephemeral update allocates a new node you allocate a new node as well.

Page 12: Planar point location -- example

12

16

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

Page 13: Planar point location -- example

1316

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

Page 14: Planar point location -- example

1416

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

29

Page 15: Planar point location -- example

1516

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

2920 2821

Page 16: Planar point location -- example

1616

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

2920 2821

2

Page 17: Planar point location -- example

17

Node copying -- analysis

The time slowdown per access step is O(1) since there is only a constant # of extra pointers per node.

What about the space blowup ?

O(1) (amortized) new nodes per update step due to nodes that would have been created by the ephemeral implementation as well.

How about nodes that are created due to node copying when the extra pointer is full ?

Page 18: Planar point location -- example

18

Node copying -- analysis

We’ll show that only O(1) of copings occur on the average per update step.

Amorized space consumption = real space consumption +

= #(used slots in live nodes)

A node is live if it is reachable from the root of the most recent version.

==> Amortized space cost of node copying is 0.

Page 19: Planar point location -- example

19

Node copying in general

Each persistent nodes has d + p + e + 1 pointers

e = extra pointers

p = predecessor pointers

1 = copy pointer.

live

4 7 115 6

Page 20: Planar point location -- example

20

Node copying in general (cont)When there is no free extra ptr copy the node.

When you copy node x, and x points to y, c(x) should point to y or to c(y) if y has been copied, update the corresponding predecessor ptr in y or c(y). Add x to the set S of copied nodes.

(S contains 1 node initially)

7

7

y

x 11

Page 21: Planar point location -- example

22

Node copying in general (cont)

7

7

11

11

y

x

In the general step it could be that when we copy x, y has already been copied

Page 22: Planar point location -- example

23

Node copying in general (cont)

Remove any node x from S,

for each node y indicated by a predecessor pointer in x

find in y the live pointer to x.

• If this ptr has version stamp i, replace it by a ptr to c(x).

• If this ptr has version stamp less than i, add to y a ptr to c(x) with version stamp i. If there is no room, copy y as before, and add it to S.

Page 23: Planar point location -- example

24

Node copying (analysis)

Actual space consumed is |S|

= #(used extra fields in live nodes)

This is smaller than |S| if e > p (Actually e ≥ p suffices if we were more careful)

So whether there were any copings or not the amortized space cost of a single update step is O(1)

= -e|S| + p|S|

Page 24: Planar point location -- example

25

The fat node method - full persistence

Does it also work for full persistence ?

5

6

NULL 15

6 7

We have a navigation problem.

Page 25: Planar point location -- example

26

The fat node method - full persistence (cont)

Maintain a total order of the version tree.

5

6 7

8

5 67 8

9

5 67 89

Page 26: Planar point location -- example

27

The fat node method - full persistence (cont)

When a new version is created add it to the list immediately after its parent.

==> The list is a preorder of the version tree.

Page 27: Planar point location -- example

28

The fat node method - full persistence (cont)

When traversing a field in version i, the relevant value is the one recorded with a version preceding i in the list and closest to it.

5

6

NULL 1

5

6 7

8 9

5 67 89

5 67 8

Page 28: Planar point location -- example

29

The fat node method - full persistence (cont)

How do we update ?

5

6

NULL 1

5

6 7

8 9

5 67 89

10

10

5 67 8910

7

Page 29: Planar point location -- example

30

The fat node method - full persistence (cont)

5

6

NULL 1

5

6 7

8 9

5 67 89

10

10

5 67 8910

7

So what is the algorithm in general ?

Page 30: Planar point location -- example

31

The fat node method - full persistence (cont)

Suppose that when we create version i we change field f to have value v.

i2

i1

i

v

f

i1 i2i

Let i1 (i2) be the first version to the left (right) of i that has a value recorded at field f

Page 31: Planar point location -- example

32

The fat node method - full persistence (cont)

We add the pair (i,v) to the list of f

Let i+ be the version following i in the version list

i2

i1

i

v

f

i1 i2i i+

If (i+ < i2) or i+ exists and i2 does not exist add the pair (i+,v’) where v’ is the value associated with i1.

v’

i+

Page 32: Planar point location -- example

33

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Fully persistent 2-4 trees with the fat node method

0

16

Page 33: Planar point location -- example

3416

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into fully persistent 2-4 trees (fat nodes)

12 1814

1

0

1

0 1

Page 34: Planar point location -- example

3516

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into fully persistent 2-4 trees (fat nodes)

12 1814

1

29

0

1

0 1

2

2

Page 35: Planar point location -- example

3616

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

2920 2821

0

1

0 1

2

2

2

Page 36: Planar point location -- example

3716

1231 1814 20 2821

. . . . . . . .. . . . . . .

. .

Insert into persistent 2-4 trees with node copying

12 1814

1

2920 2821

0

1

0 1

2

2

21

Page 37: Planar point location -- example

38

Fat node method (cont)

How do we efficiently find the right value of a field in version i ?

Store the values sorted by the order determined by the version list. Use a search tree to represent this sorted list.

To carry out a find on such a search tree we need in each node to answer an order query on the version list.

Use Dietz and Sleator’s data structure for the version list.

Page 38: Planar point location -- example

39

Fat node method (summary)

We can find the value to traverse in O(log(m)) where m is the number of versions

We get O(1) space increase per ephemeral update step

O(log m) time slowdown per ephemeral access step

Page 39: Planar point location -- example

40

Node splitting

Similar to node copying. (slightly more evolved)

Allows to avoid the O(log m) time slowdown.

Converts any pointer based data structure with constant indegrees and outdegrees to a fully persistent one.

The time slowdown per access step is O(1) (amortized).

The space blowup per update step is O(1) (amortized)

Page 40: Planar point location -- example

41

Search trees via node splitting

You get fully persistent search trees in which each operation takes O(log n) amortized time and space.

Why is the space O(log n) ?

Since in the ephemeral settings the space consumption is O(1) only amortized.

Page 41: Planar point location -- example

42

Search trees via node splitting

So what do we need in order to get persistent search trees with O(1) space cost per update (amortized) ?

We need an ephemeral structure in which the space consumption per update is O(1) on the worst case.

You can do it !

==> Red-black trees with lazy recoloring

Page 42: Planar point location -- example

43

What about deques ?

We can apply node splitting to get fully persistent deques with O(1) time per operation.

We can also transform the simulation by stacks into a real time simulation and get O(1) time solution.

What if we want to add the operation concatenate ?

None of the methods seems to extend...