- 73 Views
- Uploaded on

A Tale Of Two Simple Data Structures. Free, We Lunch.

Download Presentation
## A Tale Of Two Simple Data Structures

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### A Tale Of Two Simple Data Structures

Free, We Lunch

It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way . . .

Fat Heaps

- Meldable Heaps and Boolean Union-FindKaplan, Shafrir, TarjanSTOC 2002
- New Heap Data StructuresKaplan, Tarjan1998

Binary [Williams 64] [Floyd 64]

Binomial [Vuillemin 78]

Leftist[Crane 72]

Post Order[Harvey Zatloukal 04]

V[Peterson 87]

Fibonacci [Fredman Tarjan 87]

Skew[Sleator Tarjan 86]

[Brodal 95]

Relaxed * 2[Driscoll+ 88]

Relaxed Fibonacci[Boyapati+ 95]

[Brodal Okasaki 95]

Thin and Fat[Kaplan Tarjan 98]

Pairing[Fredman+ 86]

[Brodal 96]

Soft[Chazelle 00]

Fishspear[Fischer Paterson 94]

Redundant Counters

- We want to be able to add 1 to an arbitrary digit of a number in worst-case O(1) time.

{0, 1}

Let’s CountPositional Number System of base b

- dndn-1...d1d0 denotes

Usually the set of digits is {0,…, b-1}.

Pop Quiz

- Who cannot tell me what 1001 is?
- How about 201?

Redundant Counters

We allow one more digit in “binary numbers”: 2

(201)2= 2*4 + 1= 9

(121)2= 1*4 + 2*2 + 1= 9

Regularity

A counter is regular iff between every two 2’s there is a digit other than 1.

Regularity does not entail unique representation.

- 2002

- 2120

From here on,we operate onlyonregular counters.

(2)2

(10)2

Exposure

Let’s call 0 and 2 “special”.

If the last special digit of a counter is d, then the counter is d-exposed.

2012 2-exposed

2011 0-exposed

0-exposed

At worst turn into a2-exposed (regular) counter

2-exposed

Can turn irregular

+1 Observation2011 2012

2021 2022

2020 2021

2012 2013 ???

2010 2011

Fixing 2-exposure

This is the time for carry. We fix the rightmost 2.

x is 0-exposed

x21*

We know how to add 1 to a 0-exposed number

(x+1)01*

Arbitrary Position

Use fix to match original exposure, delete block when needed

- If originally the prefix is 2-exposed, done.
- Otherwise (0-exposed), fix.

Question is how to locate the rightmost 2 in the prefix…

xdiy

Implementation

Uses worst-case resizable array (doubling + copy on write)

[Brodal 96] (easier to explain than [Kaplan Tarjan 98]):

Mark blocks of digits with the form

and leave the other digits unmarked.

21*0

Redundant Counters

We can implement a counter in any base so thatan arbitrary digit can be incremented in O(1) time.

The length of the counter is logarithmic in its value.

Structure of Amortization

The 2-for-1 phenomena

- Finger Search Tree [Guibas+ 77]
- Implicit Binomial Queue [Carlsson+ 88]
- Persistent List [Kaplan Tarjan 95]
- Heaps [Brodal 95] [Brodal 96]

Fat Heaps

A fat heap is a forest of almost heap-ordered fat trees,with at most 3 Fk per k,and at most 2 heap-order violations per rank.

Other Ingredients:

- a minimum pointer to the minimum element
- a redundant ternary root counter to control the trees
- a redundant binary violation counter to control the violations

Insert(h, x)

Make a F0 out of x

Add to the root counter, perform fix by linking

3 Fk-1

Fk

Fk-1

Fk-1

Fk-1

Fk-1

fix

Fk-1

Fk-1

DecreaseKey(h, x, )

Reduce x by

If x is now smaller than the minimum, swap.

If x is now a violation, add 1 to the r-th digit of the violation counter where r is the rank of x.

But how to fix two rank r violations into one rank (r+1)?

Fixing Violations – Step 1

Arrange the violations to have the same parent, assume a < b

a

b

a

b

exchange

v

w

c

c

w

v

r

r

r

r

r

r

r

r

Fixing Violations – Step 2a

If the parent is of rank r+1, assuming v < w:

(x can be a new violation at its parent)

b

v

r+1

r+1

re-link

w

v

w

b

r

r

r

r

Fixing Violations – Step 2b

If the parent is of rank larger than r+1:

b

b

r+5

r+5

re-link

e

w

v

v

f

g

r+1

r

r

r+1

r

r

f

g

e

w

r

r

r

r

DeleteMin(h)

We have all the time in the world, WAH HA HA!

- Fix all violations in O(log n) time

Now similar to Binomial Heaps

- Remove the minimum root, exposing its O(log n) children
- Insert each child one by one into root counter
- Scan for minimum among the roots

Meld(h1, h2)

Assume h2 is not the larger heap

- Fix all violations in h2 in O(log n) time
- Insert trees in h2 one by one into h1
- Update the minimum pointer if necessary

Dynamic Connectivity

- Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, MST, 2-Edge and BiconnectivityHolm, de Lichtenberg, ThorupJACM 2001

Dynamic Connectivity

Given a fixed set of n vertices

Dynamic Connectivity

Insert an edge

Dynamic Connectivity

Insert an edge

Dynamic Connectivity

Delete an edge

n1/2, O(1)[Eppstein+ 92]

log3 n, log n / log log n[Henzinger King 95]

log2 n, log n / log log n [Henzinger Thorup 96]

n1/3 log n, O(1) [Henzinger King 97]

log2 n, log n / log log n[Holm+ 98]

Jump To The

- Reduction: dynamic maintenance a spanning forest

Edge Insertion

If the edge creates a cycle, no change is needed

Edge Insertion

Otherwise the edge links two disjoint trees

Edge Deletion

If the edge is not a tree edge, no change is needed

Edge Deletion

If it is a tree edge, then need to find a replacement if exists.

Edge Deletion

If it is a tree edge, then need to find a replacement if exists.

Dynamic Trees

Basic Abstraction:

- Link two disjoint trees with a new edge
- Cut a tree edge and produce two trees
- “Are u and v in the same tree?”

We need one more:

- Report the size of the tree containing u

O(log n)

O(log n)

O(log n)

O(log n)

Lower Bound

Logarithmic Lower Bounds in the Cell-Probe ModelPǎtraşcu, DemaineSIAM JoC, to appear

Dynamic Connectivity requires (logn) query & update time

- Holds even for trees
- So this black box reduction may be a bad idea

Terminology

G is the dynamic graph.

F is a spanning forest of G.

An edge is either a tree edge or a non-tree edge.

Level

Attach a level label to each edge, l(e)

For each i, let Fi denote the subforest of F induced by edges of level at least i.

Invariant 2

F is a maximumly spanning forest of G with respect to l.

- If (v, w) is a non-tree edge of level i, thenv and w are connected in a tree in Fi.

Implementation Note

For each level i

- we maintain Fi in dynamic tree structure.
- for each vertex, we maintain a list of level i incident tree edges and a list of level i incident non-tree edges. (So each vertex has 2logn lists.)

Space usage will be O(m + n log n)

Insert(e)

Inserted e into G at level 0.

If e connects two trees, then add it to F=F0.

- Both invariants are still satisfied.

Delete(e)

If non-tree edge, then simply delete from G. Done.

Else search for a replacement of the highest possible level(to restore invariant 2).

- Which level should we start searching?

By invariant 2, F is maximumly spanning, so the replacement cannot be at a level higher than e.

Replace((v,w), j)

Assume that there is no replacement edge on level > j.

Let Tv, Tw be the two trees in Fj containing v and w.

v

w

Replace((v,w), j)

Before deleting (v, w), this whole tree is at most n / 2j.

So Tv is at most n / 2j+1.

v

w

Replace((v,w), j)

So we can promote all tree edges in Tv to level j+1 while preserving invariant 1.

v

j+1

v

w

j

Replace((v,w), j)

If there is no level j incident edges left and j > 0,then call Replace((v,w), j-1).

v

w

j

v

w

j-1

Running Time – Insert

Inserting (u, v) at level 0 costs O(logn) actual time

- Is u is connected to v in F?
- Link if not

Promoting an edge costs O(logn) actual time

- Connectivity query to discover that it connects inside a tree

Running Time – Delete

Deleting a non-tree edge takes O(logn) time

- Erase it from the incident list in all levels

Deleting a tree-edge takes O(log2n) time

- Cut forests on all levels
- O(logn) recursive call to Replace, each costs O(logn) to compute tree size (plus scanning cost amortized to insert)
- If a replacement edge is found, O(logn) linking.

Open Question – 1

“Deamortize” Fibonacci Heaps without using arrays

- Actually even Fibonacci Heaps use arrays…(during meld)

Open Questions – 2

O(logn) time dynamic connectivity, randomized or not

- Current lower bound uses only trees to mess us up…(dynamic connectivity on graphs may have a higher lowerbound)

Open Questions – 3

Worst-Case Polylogarithmic Dynamic Connectivity

- But can we deamortize Holm et. al’s algorithm?

Download Presentation

Connecting to Server..