Checking & Spot-Checking the Correctness of Priority Queues - - PowerPoint PPT Presentation

checking spot checking the correctness of priority queues
SMART_READER_LITE
LIVE PREVIEW

Checking & Spot-Checking the Correctness of Priority Queues - - PowerPoint PPT Presentation

Checking & Spot-Checking the Correctness of Priority Queues Matthew Chu & Sampath Kannan (UPenn) Andrew McGregor (UCSD) Memory Checking Memory Checking Your resources: A lot of cheap unreliable memory and a little expensive reliable


slide-1
SLIDE 1

Checking & Spot-Checking the Correctness of Priority Queues

Matthew Chu & Sampath Kannan (UPenn) Andrew McGregor (UCSD)

slide-2
SLIDE 2

Memory Checking

slide-3
SLIDE 3

Memory Checking

  • Your resources: A lot of cheap unreliable memory

and a little expensive reliable memory.

slide-4
SLIDE 4

Memory Checking

  • Your resources: A lot of cheap unreliable memory

and a little expensive reliable memory.

  • Your challenge: Can you make use of the cheap

memory? Want to identify (but not correct) any errors introduced by a malicious adversary.

slide-5
SLIDE 5

Memory Checking

  • Your resources: A lot of cheap unreliable memory

and a little expensive reliable memory.

  • Your challenge: Can you make use of the cheap

memory? Want to identify (but not correct) any errors introduced by a malicious adversary.

  • Related Work:

Program Checking

[Blum, Kannan ’95]

Memory Checking

[Blum et al. ’94]

Checking linked Data Structures

[Amato, Loui ’94]

slide-6
SLIDE 6

Priority Queues

slide-7
SLIDE 7

Priority Queues

  • Priority Queue:

Supports a sequence of inserts and extract-min’s. Is “correct” if each extract-min returns the smallest value inserted and not extracted.

slide-8
SLIDE 8

Priority Queues

  • Priority Queue:

Supports a sequence of inserts and extract-min’s. Is “correct” if each extract-min returns the smallest value inserted and not extracted.

  • Interaction Sequence: c1, c2, ..., c2n where ct is either

(u,t) if the user inserts u at step t (u,t’) if the user extract-min’s at step t and PQ claims u, inserted at time t’, is the min.

slide-9
SLIDE 9

Priority Queues

  • Priority Queue:

Supports a sequence of inserts and extract-min’s. Is “correct” if each extract-min returns the smallest value inserted and not extracted.

  • Interaction Sequence: c1, c2, ..., c2n where ct is either

(u,t) if the user inserts u at step t (u,t’) if the user extract-min’s at step t and PQ claims u, inserted at time t’, is the min.

  • Example: Insert 5, Insert 4, Extract-min, Insert 7,...

would correspond to the sequence (5,1), (4,2), (4,2), (7,4), ... if the PQ was correct.

slide-10
SLIDE 10

The Checking Problem

slide-11
SLIDE 11

The Checking Problem

  • Input: A sequence c1, c2, ... , c2n with n inserts and n

extract-mins.

slide-12
SLIDE 12

The Checking Problem

  • Input: A sequence c1, c2, ... , c2n with n inserts and n

extract-mins.

  • Goal: Fail the stream with high probability if it is

not correct and pass otherwise.

slide-13
SLIDE 13

The Checking Problem

  • Input: A sequence c1, c2, ... , c2n with n inserts and n

extract-mins.

  • Goal: Fail the stream with high probability if it is

not correct and pass otherwise.

  • Constraints: The interaction sequence is observed

as a stream and has limited space.

slide-14
SLIDE 14

The Checking Problem

  • Input: A sequence c1, c2, ... , c2n with n inserts and n

extract-mins.

  • Goal: Fail the stream with high probability if it is

not correct and pass otherwise.

  • Constraints: The interaction sequence is observed

as a stream and has limited space.

  • We are interested in offline checkers that identify

errors by the end of the interaction sequence.

slide-15
SLIDE 15

Results

slide-16
SLIDE 16

Results

  • Checkers:

A randomized, offline, O(√n log n)-space checker that identifies errors with prob. 1-1/n. Any randomized, offline checker of a “certain type” requires Ω(√n) space. Online or deterministic requires Ω(n) space.

slide-17
SLIDE 17

Results

  • Checkers:

A randomized, offline, O(√n log n)-space checker that identifies errors with prob. 1-1/n. Any randomized, offline checker of a “certain type” requires Ω(√n) space. Online or deterministic requires Ω(n) space.

  • Spot-Checker:

A randomized, offline, O(ε-1 log2 n)-space spot- checker that identifies a priority queue that is “ε-far” from correct with prob. 1-1/n.

slide-18
SLIDE 18

1: Preliminaries 2: Checking 3: Spot-Checking

slide-19
SLIDE 19

1: Preliminaries 2: Checking 3: Spot-Checking

slide-20
SLIDE 20

Correctness

slide-21
SLIDE 21

Correctness

  • Thm: An interaction sequence is correct iff it

satisfies: C1: {(u,t)}={(u,t)} C2: For all cs=(u,t): t<s C3: For all ctb =(u,ta) and csb =(v,sa): ((u,ta) < (v,sa)) then (sb<ta or tb<sa)

  • Proof Idea: If correct then clearly C1, C2, & C3. For
  • ther direction consider first incorrect extract-

min...

slide-22
SLIDE 22

Correctness

  • Thm: An interaction sequence is correct iff it

satisfies: C1: {(u,t)}={(u,t)} C2: For all cs=(u,t): t<s C3: For all ctb =(u,ta) and csb =(v,sa): ((u,ta) < (v,sa)) then (sb<ta or tb<sa)

  • Proof Idea: If correct then clearly C1, C2, & C3. For
  • ther direction consider first incorrect extract-

min...

slide-23
SLIDE 23

Hashing

slide-24
SLIDE 24

Hashing

  • Thm (Naor & Naor): Can construct a hash function h
  • n length n strings such that

It uses O(lg n) random bits and can be constructed in O(lg n) space even if the characters of each string are revealed in an arbitrary order. Pr[h(x) = h(y)] ≤ δ if x = y.

slide-25
SLIDE 25

Hashing

  • Thm (Naor & Naor): Can construct a hash function h
  • n length n strings such that

It uses O(lg n) random bits and can be constructed in O(lg n) space even if the characters of each string are revealed in an arbitrary order.

  • What it means for us:

Let xt be (u,t) if u was inserted at time t Let yt be (u,t) if an extract returns (u,t) Hence can easily check C1: {(u,t)}={(u,t)} Pr[h(x) = h(y)] ≤ δ if x = y.

slide-26
SLIDE 26

1: Preliminaries 2: Checking 3: Spot-Checking

slide-27
SLIDE 27

Checking Results

  • Thm: A randomized, offline, O(√n lg n)-space

checker that identifies errors with prob. 1-1/n.

  • Thm: Any randomized online checker that is

correct with prob. 3/4 requires Ω(n/lg n) space.

  • Thm: Any deterministic offline checker requires

Ω(n) space.

  • Outline why Ω(√n) space looks necessary for

randomized, offline checkers...

slide-28
SLIDE 28
  • Key Idea: cta=(u,t) should imply that all elements

inserted before ta and not extracted are greater than cta

Algorithm Intuition

slide-29
SLIDE 29
  • Key Idea: cta=(u,t) should imply that all elements

inserted before ta and not extracted are greater than cta

Algorithm Intuition

Value t

slide-30
SLIDE 30
  • Key Idea: cta=(u,t) should imply that all elements

inserted before ta and not extracted are greater than cta

Algorithm Intuition

Value t

slide-31
SLIDE 31
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

slide-32
SLIDE 32
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

slide-33
SLIDE 33
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

slide-34
SLIDE 34
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

slide-35
SLIDE 35
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

slide-36
SLIDE 36
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

slide-37
SLIDE 37
  • Split sequence into √n-length Epochs
  • Identify errors within present epoch immediately
  • Maintain lower-bound on contents of past epochs.

Algorithm Outline

Value t

Epoch-1 Epoch-2 Epoch-3 Epoch-4 Epoch-5 Epoch-6

???

slide-38
SLIDE 38

Algorithm Detail

For k in [2√n], let f(k)=0 For i=1 to 2√n: Let Buffer be empty For j in Epoch-i={(i-1)√n+1,...,i√n}: If ci=(u,t), add ci to B If ci=(u,t): If t in Epoch-k (k<i) and f(k)>ci then FAIL! If t in Epoch-i and ci > min Buffer then FAIL! Remove ci from Buffer (if present) For k<i, let f(k)=max(f(k),ci) Let f(i)=min Buffer

slide-39
SLIDE 39

Proof of Correctness

slide-40
SLIDE 40

Proof of Correctness

  • We may assume C1 and C2 are satisfied.
slide-41
SLIDE 41

Proof of Correctness

  • We may assume C1 and C2 are satisfied.
  • Consider error: ctb=(u,ta) and csb=(v,sa) such that

(u,ta)<(v,sa) and ta<sb<tb:

v u ta sb tb

slide-42
SLIDE 42

Proof of Correctness

  • We may assume C1 and C2 are satisfied.
  • Consider error: ctb=(u,ta) and csb=(v,sa) such that

(u,ta)<(v,sa) and ta<sb<tb:

  • Let ta and sb be in Epoch-i and Epoch-j resp.

v u ta sb tb

slide-43
SLIDE 43

Proof of Correctness

  • We may assume C1 and C2 are satisfied.
  • Consider error: ctb=(u,ta) and csb=(v,sa) such that

(u,ta)<(v,sa) and ta<sb<tb:

  • Let ta and sb be in Epoch-i and Epoch-j resp.
  • Case 1: If i=j then v>min Buffer and hence we fail

at time sb (or before.)

v u ta sb tb

slide-44
SLIDE 44

Proof of Correctness

  • We may assume C1 and C2 are satisfied.
  • Consider error: ctb=(u,ta) and csb=(v,sa) such that

(u,ta)<(v,sa) and ta<sb<tb:

  • Let ta and sb be in Epoch-i and Epoch-j resp.
  • Case 1: If i=j then v>min Buffer and hence we fail

at time sb (or before.)

  • Case 2: If i<j then f(i)≥(v,sb) and hence we fail at

time tb (or before.)

v u ta sb tb

slide-45
SLIDE 45

Online or Deterministic?

  • Thm: Any online checker that is correct with
  • prob. 3/4 requires Ω(n/lg n) space.
  • Thm: Any offline deterministic checker requires

Ω(n) space.

slide-46
SLIDE 46

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

slide-47
SLIDE 47

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

slide-48
SLIDE 48

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

slide-49
SLIDE 49

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

(2+x1,1), (4+x2,2), ... ,(2n+xn,n)

slide-50
SLIDE 50

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

(2+x1,1), (4+x2,2), ... ,(2n+xn,n)(2+y1,1), (4+y2,2), ... ,(2n+yn,n)

slide-51
SLIDE 51

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

  • Checker fails after (4+yj,j) iff prefixes equal.

(2+x1,1), (4+x2,2), ... ,(2n+xn,n)(2+y1,1), (4+y2,2), ... ,(2n+yn,n)

slide-52
SLIDE 52

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

  • Checker fails after (4+yj,j) iff prefixes equal.

MEMORY STATE OF ALGORITHM

(2+x1,1), (4+x2,2), ... ,(2n+xn,n)(2+y1,1), (4+y2,2), ... ,(2n+yn,n)

slide-53
SLIDE 53

“Is the length i prefix of x and y equal?” Lemma: Needs Ω(n/lg n) bits transmitted.

[Chakrabarti, Cormode, McGregor ’07]

Alice

length n binary string x

Bob

length n binary string y & index i in [n]

  • Assume there exists a S-space online

checker that works with prob. 3/4.

  • Checker fails after (4+yj,j) iff prefixes equal.
  • Thm: S=Ω(n/lg n)

MEMORY STATE OF ALGORITHM

(2+x1,1), (4+x2,2), ... ,(2n+xn,n)(2+y1,1), (4+y2,2), ... ,(2n+yn,n)

slide-54
SLIDE 54

1: Preliminaries 2: Checking 3: Spot-Checking

slide-55
SLIDE 55

Spot-Checking

slide-56
SLIDE 56

Spot-Checking

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

slide-57
SLIDE 57

Spot-Checking

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Consider interaction sequence c1, ... , c2n and
  • perm. π of [2n]. Define new interaction sequence

d1, ... , d2n where dπ(i) = (u,π(i)) if ci= (u,i) dπ(i) = (u,π(j)) if ci= (u,j)

slide-58
SLIDE 58

Spot-Checking

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Consider interaction sequence c1, ... , c2n and
  • perm. π of [2n]. Define new interaction sequence

d1, ... , d2n where dπ(i) = (u,π(i)) if ci= (u,i) dπ(i) = (u,π(j)) if ci= (u,j)

  • Say interaction sequence c1, ... , c2n is ε-far if no

permutation with less than εn rearrangements results in a correct interaction sequence.

slide-59
SLIDE 59

Revealing Tuples

slide-60
SLIDE 60

Revealing Tuples

  • Say (u,ta) is a revealing if there exists

csb=(v,sa)>(u,ta) and ctb=(u,ta) such that ta<sb<tb:

v u ta sb tb

slide-61
SLIDE 61

Revealing Tuples

  • Say (u,ta) is a revealing if there exists

csb=(v,sa)>(u,ta) and ctb=(u,ta) such that ta<sb<tb:

  • Thm: An interaction sequence that is ε-far from

being correct has at least εn revealing tuples.

v u ta sb tb

slide-62
SLIDE 62

Revealing Tuples

  • Say (u,ta) is a revealing if there exists

csb=(v,sa)>(u,ta) and ctb=(u,ta) such that ta<sb<tb:

  • Thm: An interaction sequence that is ε-far from

being correct has at least εn revealing tuples.

  • Proof:

Find first incorrect extract-min, say csb=(v,sa). Since this isn’t minimum element, there exists (u,ta) and ctb=(u,ta) such that ta<sb<tb. Moving tb to sb reduces # of revealing tuples. Continue until sequence is correct.

v u ta sb tb

slide-63
SLIDE 63

Correctness

slide-64
SLIDE 64

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

slide-65
SLIDE 65

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Proof:
slide-66
SLIDE 66

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Proof:

Samples O(ε-1 lg2 n) insertions. Call these S.

slide-67
SLIDE 67

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Proof:

Samples O(ε-1 lg2 n) insertions. Call these S. W.h.p. there exists a revealing tuple (u,ta) in S.

slide-68
SLIDE 68

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Proof:

Samples O(ε-1 lg2 n) insertions. Call these S. W.h.p. there exists a revealing tuple (u,ta) in S. Monitor elements between the insertion and extraction of each element in S.

slide-69
SLIDE 69

Correctness

  • Thm: A randomized, offline, O(ε-1 lg2 n)-space

spot-checker that fails a PQ queue that is “ε-far” from correct w.h.p.

  • Proof:

Samples O(ε-1 lg2 n) insertions. Call these S. W.h.p. there exists a revealing tuple (u,ta) in S. Monitor elements between the insertion and extraction of each element in S. Will identify csb=(v,sa)>(u,ta) and ctb=(u,ta) such that ta<sb<tb.

slide-70
SLIDE 70

Summary

  • Checkers:

A randomized, offline, O(√n log n)-space checker that identifies errors with prob. 1-1/n. Any randomized, offline checker of a “certain type” requires Ω(√n) space. Online or deterministic requires Ω(n) space.

  • Spot-Checker:

A randomized, offline, O(ε-1 lg2 n)-space spot- checker that identifies a priority queue that is “ε-far” from correct with prob. 1-1/n.

  • ... and that’s how you mind you P.Q.’s!