a tale of two simple data structures n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
A Tale Of Two Simple Data Structures PowerPoint Presentation
Download Presentation
A Tale Of Two Simple Data Structures

Loading in 2 Seconds...

play fullscreen
1 / 78

A Tale Of Two Simple Data Structures - PowerPoint PPT Presentation


  • 72 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'A Tale Of Two Simple Data Structures' - donnan


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
slide2
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
Fat Heaps
  • Meldable Heaps and Boolean Union-FindKaplan, Shafrir, TarjanSTOC 2002
  • New Heap Data StructuresKaplan, Tarjan1998
slide4

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
Redundant Counters
  • We want to be able to add 1 to an arbitrary digit of a number in worst-case O(1) time.
let s count

2

{0, 1}

Let’s Count

Positional Number System of base b

  • dndn-1...d1d0 denotes

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

pop quiz
Pop Quiz
  • Who cannot tell me what 1001 is?
  • How about 201?
redundant counters1
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
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
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

1 observation
0-exposed

At worst turn into a2-exposed (regular) counter

2-exposed

Can turn irregular

+1 Observation

2011  2012

2021  2022

2020  2021

2012  2013 ???

2010  2011

fixing 2 exposure
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*

add 1 in o 1 time
Add 1 in O(1) Time

If the counter is 2-exposed, fix.

Add 1 as usual.

arbitrary position
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
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

pointer diagram
Pointer Diagram

. . .

d2

d1

d0

case 1 of 40
Case 1 of 40

211021110

211022110+1

211102110fix

211110110fix

211110110 reform blocks

case 2 of 40
Case 2 of 40

211021110

211021210+1

211101210fix

211102010fix

211102010 reform blocks

redundant counters2
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
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]
heap order
Heap Order

5

11

8

42

16

7

9

violations
Violations

5

11

8

42

3

7

9

fat trees
Fat Trees

F0 is a single node

Fk is threeFk-1 linked together:

Fk-1

Fk-1

Fk-1

nodes
Nodes

4 pointers

1 word

5

r

12

7

r-1

r-1

fat heaps1
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
slide33
MakeHeap()

Initialize the two counters to 0

FindMin()

Return the minimum pointer

insert h x
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
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
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
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
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
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 h 1 h 2
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
Dynamic Connectivity
  • Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, MST, 2-Edge and BiconnectivityHolm, de Lichtenberg, ThorupJACM 2001
dynamic connectivity1
Dynamic Connectivity

Given a fixed set of n vertices

dynamic connectivity2
Dynamic Connectivity

Insert an edge

dynamic connectivity3
Dynamic Connectivity

Insert an edge

dynamic connectivity4
Dynamic Connectivity

Delete an edge

dynamic connectivity5
Dynamic Connectivity

Are u and v connected right now?

u

v

slide48

m1/2, O(1)[Frederickson 83]

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
Jump To The
  • Reduction: dynamic maintenance a spanning forest
edge insertion
Edge Insertion

If the edge creates a cycle, no change is needed

edge insertion1
Edge Insertion

Otherwise the edge links two disjoint trees

edge deletion
Edge Deletion

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

edge deletion1
Edge Deletion

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

edge deletion2
Edge Deletion

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

dynamic trees
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
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
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
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 1
Invariant 1

The maximal number of vertices in a tree in Fi is n / 2i.

  • So the maximal level is logn.
invariant 2
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
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
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
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
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 j1
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 j2
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 j3
Replace((v,w), j)

Scan level j edges incident on Tv. Suppose we are scanning f.

v

j+1

v

w

j

replace v w j4
Replace((v,w), j)

If f connects Tv and Tw, return.

v

j+1

v

w

j

f

replace v w j5
Replace((v,w), j)

Otherwise, f connects inside Tv. Promote f. Scan next edge.

v

f

j+1

v

w

f

j

replace v w j6
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
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
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
Open Question – 1

“Deamortize” Fibonacci Heaps without using arrays

  • Actually even Fibonacci Heaps use arrays…(during meld)
open questions 2
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
Open Questions – 3

Worst-Case Polylogarithmic Dynamic Connectivity

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