58
Introduction: context and goals EB Method Amortized complexity An abstract specification of a priority queue Implementing priority queues using skew heaps Conclusions The teaching of Data Structures: A Balanced Presentation of Skew Heaps Marc Guyomard ENSSAT/IRISA Université de Rennes 1 – Université Européenne de Bretagne 6, rue de Kerampont, F-22305 Lannion France [email protected] Nantes – June 7 th 2010 TFM The B formal Method 1/58 Marc Guyomard A Balanced Presentation of Skew Heaps

The teaching of Data Structures: A Balanced Presentation of Skew

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

The teaching of Data Structures:A Balanced Presentation of Skew Heaps

Marc Guyomard

ENSSAT/IRISAUniversité de Rennes 1 – Université Européenne de Bretagne

6, rue de Kerampont, F-22305 Lannion [email protected]

Nantes – June 7th 2010TFM The B formal Method

1/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

2/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

3/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Which level?

First year in ”école d’ingénieurs“ (21 years old) ∼:1 Germany: Technical universities, just after Vor Diplom2 United Kingdom: last year of Bachelor of science or Engineer3 United States : Bachelor of Science, third year4 Belgium: first year of ”Ingénieur Civil“5 Spain: first year of ”specialized Engineering Cycle“

4/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Goals (of the paper)

1 A plea for a better balance between the (at least) two aspectsof teaching data structures

complexity analysis: "a serious activity"algorithm production: "an easily acquire know-how"

2 An improvement of the didactic of skew heapsa tighter definitiona new amortized analysis

5/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

6/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Principles

Abstract specification + Concrete specification + Abstraction function + Calculation=

Operation representation

Representation of the concrete operations

Abstract specification

• Abstract support

• Specification of the operations

Concrete specification

• Concrete support

• Specification of the concrete operations

Calculation

Abstraction function

7/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Some keys words about EB method

1 Homomorphism: A(fc (x, y)) = fa(A(x),A(y))

2 Operations of the abstract type are functions (in the functional programming meaning)

3 The concrete operations are unknown

4 Calculation of the unknown (the concrete operation) fc?

A(fc (. . .))= Property 1

. . .= Property nA(exp)

Thus exp is an obvious solution to the equation (in fc (. . .)) A(fc (. . .)) = A(exp)

5 Calculation is generally done under the assumption of a condition destined to become a guard

6 One formal refinement

8/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

9/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Amortized complexity: Principles

Let o be a kind of operation and o1; o2; . . . on a sequence of calls too. The occasionally important cost of certain oi can becompensated by the surrounding calls.

Traditional (average) complexity: summation over all possibleconfigurations for a given size of data (with a probalisticmodel)Amortized analysis: average over a sequence of operations

10/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Amortized complexity: Definition (potential method)

A potential function Φ ∈ support 7→ R+ such as, if s0 is theinitial configuration and sj any configuration then Φ(s0) = 0and Φ(sj) ≥ 0R(oi ): actual cost of operation oiM(oi ) = R(oi ) + Φ(si )− Φ(si−1)

Thus (substitution)

Σi ·(i ∈ 1 .. k | M(oi )) = Σi ·(i ∈ 1 .. k | R(oi )) + Φ(sk)

So

Σi ·(i ∈ 1 .. k | M(oi )) ≥ Σi ·(i ∈ 1 .. k | R(oi ))

11/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

12/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Data structures: a short history in four periods

1 Period 1 (1950 to 1960): pioneers, binary search trees, hashingmethods,...

2 Period 2 (1960 to 1980): explicitly balanced data structures:Avl, B-trees, etc.

3 Period 3 (late 70): self-adjusting data structures andamortized analysis: splay trees, skew heaps,...

4 Period 4 (late 80): random data structures: randomizedtreaps, skip lists, randomized binary search trees,...

Periods 3 and 4: back to simplicity provided efficiency is (roughly)preserved.

13/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Priority queue: informal definition

Priorities: integers. The lowest the number is, the highest thepriority isElements line up, waiting for a "service"Main operations:

Creating an empty priority queue,Insertion of an element,Removal of (one of) the element with the highest priorityObserving the highest priority(Sometimes) merging two priority queues

A priority queue is a bag equipped with some specific operations

14/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Priority queue: scores of applications

Process/memory management in operating systemsSimulationFile compression (Huffman code)Search in graphsSortingMessage management in computer networksSpams filteringComputational geometry...

15/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Priority queue a formal abstract specification

bags sets�� ∅

J. . .K {. . .}bMin min

u ∪− −

abstractType pqabst= (pqAbst, (pqEmpty, pqAdd, pqRem), (pqPrio))support

f ∈ B(N) ⇔ f ∈ pqAbstoperations

function pqEmpty() ∈ pqAbst = ��;

function pqAdd(v, f ) ∈ N× pqAbst → pqAbst = JvK u f;

function pqRem(f ) ∈ pqAbst 7→ pqAbst =pre f 6= �� then f − JbMin(f )K end

;function pqPrio(f ) ∈ pqAbst 7→ N = pre f 6= �� then bMin(f ) end

auxiliaryOperationSpecifications

function pqMerge(f , f ′) ∈ pqAbst × pqAbst→ pqAbst = f u f ′

end

16/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

17/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Skew heaps – Traditional support

1

6

7

9

8

2

5

6 8

3

4

1

7

9 8

2

5

6 8

3

4

support1) 〈 〉 ∈ sh2) g ∈ sh ∧ d ∈ sh ∧ r ∈ N ∧ r = bMin(A(〈g, r, d〉)) ⇒ 〈g, r, d〉 ∈ sh

A(t) provides the bag of the values present in t

18/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

skew heaps – A tighter support

1

6

7

9

8

2

5

6 8

3

4

1

7

9 8

2

5

6 8

3

4

support1) 〈 〉 ∈ sh2) r ∈ N ⇒ 〈〈 〉, r, 〈 〉〉 ∈ sh3) g ∈ sh − {〈 〉} ∧ d ∈ sh ∧ r ∈ N ∧ r = bMin(A(〈g, r, d〉))

⇒〈g, r, d〉 ∈ sh

19/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

A: the abstraction function

abstractionFunctionfunction A(f ) ∈ sh→ pqAbst =if f = 〈 〉 →

��| f = 〈g, r, d〉 →A(g) u JrK uA(d)

fi

1

6

7 8

2

5

6 8

3

4

A(. . .)J1, 2, 3, 4, 5, 6, 7, 8K

20/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

concreteType sh= (sh, (pqEmpty_sh, pqAdd_sh, pqRem_sh)(pqPrio_sh))refines pqabstsupport

. . .abstractionFunction

. . .operationSpecifications

function pqEmpty_sh() ∈ sh = q : (q ∈ sh ∧ A(q) = pqEmpty());

function pqAdd_sh(v, f ) ∈ N× sh→ sh =q : (q ∈ sh ∧ A(q) = pqAdd(v,A(f )))

;function pqRem_sh(f ) ∈ sh 7→ sh =preA(f ) 6= ��

thenq : (q ∈ sh ∧ A(q) = pqRem(A(f )))

end;

function pqPrio_sh(f ) ∈ sh 7→ N =preA(f ) 6= ��

thenpqPrio(A(f ))

endauxiliaryOperationSpecifications

function merge(f , f ′) ∈ sh × sh→ sh =q : (q ∈ sh ∧ A(q) = pqMerge(A(f ),A(f ′)))

end

21/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

A(merge(f , f ′))= Specification of merge

pqMerge(A(f ),A(f ′))= Specification of pqMergeA(f ) uA(f ′) (5.1)

A primary induction on f . Base case f = 〈 〉:

A(f ) uA(f ′)= SubstitutionA(〈 〉) uA(f ′)

= Definition of A��uA(f ′)

= �� neutral element of uA(f ′)

Hence:

f = 〈 〉 →merge(f , f ′) = f ′

22/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

After a secondary induction on f ′ and the corresponding base casef ′ = 〈 〉:

f = 〈g , r , d〉 →f ′ = 〈 〉 →

merge(f , f ′) = f

23/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Starting from formula 5.1: A(f ) uA(f ′):

A(f ) uA(f ′)= SubstitutionsA(〈g , r , d〉) uA(〈g ′, r ′, d ′〉)

= Definition of AA(g) u JrK uA(d) uA(g ′) u Jr ′K uA(d ′) (5.2)

Case analysis, depending on r ≤ r ′ or r > r ′. We focus on r ≤ r ′.

24/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Combinatorial explosion control

u is commutative. A(g) u JrK uA(d) uA(g ′) u Jr ′K uA(d ′) canbe reorganized in various (144) equivalent formulas. Two of them:

A(g) u JrK u (A(d) uA(f ′))

and

(A(d) uA(f ′)) u JrK uA(g)

Thanks to the tighten support we can prune out unproductivesolutions

25/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Two examples

f f ′ A(g) u JrK u (A(d) uA(f ′)) (A(d) uA(f ′)) u JrK uA(g)

5 75

7

5

7

26/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Carrying on from the second solution

(A(d) uA(f ′)) u JrK uA(g)= Specification of pqMerge

(pqMerge(A(d),A(f ′)) u JrK uA(g)= Specification of mergeA(merge(d , f ′)) u JrK uA(g)

= Definition of AA(〈merge(d , f ′), r , g〉)

Thus the following guarded equation:

f = 〈g , r , d〉 →merge(f , f ′) = 〈merge(d , f ′), r , g〉

27/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Representation of merge

Hence we have calculated:

function merge(f , f ′) ∈ sk × sk→ sk =if f = 〈 〉 →

f ′| f = 〈g, r, d〉 →

if f ′ = 〈〉 →f

| f ′ = 〈g ′, r ′, d′〉 →if r ≤ r ′ →〈merge(d, f ′), r, g〉

| r ′ < r →〈merge(d′, f ), r ′, g ′〉

fifi

fi

Worst solution is in O(n + n′), not in O(log(n + n′)). Is it in O(log(n + n′)) in the amortized sense ?

28/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

The potential function

A preliminary notation

a ∈ sh→ N{〈 〉 = 1〈g, r, d〉 = g + d

a returns the size of a plus 1.

Φ(〈 〉) = 0Φ(〈g, r, d〉) = Φ(g) + ϕ(g, d) + Φ(d)Φ((f , f ′)) = Φ(f ) + Φ(f ′)

Φ(f ) counts the s-unbalanced trees (unbalanced in terms of size) in favour of the right-hand side.

29/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

Φ: An example

11

60

70

20

51

60 80

100

30

Φ2

30/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

R the actual cost

From the representation of merge (number of recursive calls to merge)

R(merge(〈 〉, f ′) = 0R(merge(f , 〈 〉) = 0 (for f 6= 〈 〉)

R(merge(〈g, r, d〉, 〈g ′, r ′, d′〉)) = 1 +

{R(merge(d, f ′)) if r ≤ r ′

R(merge(d′, f )) if r ′ < r

From the definition of amortized complexity:

M(merge(f , f ′)) = R(merge(f , f ′)) + Φ(merge(f , f ′))− Φ((f , f ′))

31/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

After removing R fromM:

M(merge(〈 〉, f ′)) = 0M(merge(f , 〈 〉)) = 0 (for f 6= 〈 〉)

M(merge(f , f ′)) = 1 +

{M(merge(d, f ′)) + ϕ(merge(d, f ′), g)− ϕ(g, d) if r ≤ r ′

M(merge(d′, f )) + ϕ(merge(d′, f ), g ′)− ϕ(g ′, d′) if r ′ < r

32/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Skew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

The result

After a long series of quite easy but boring calculations we obtain:

M(merge(f , f ′)) ≤ 3. log(f + f ′)

Thus:

M(merge(f , f ′)) is in O(log(f + f ′))

33/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

1 Introduction: context and goals

2 EB Method

3 Amortized complexity

4 An abstract specification of a priority queue

5 Implementing priority queues using skew heapsSkew heaps: an informal outlineSkew heaps: the abstraction functionSkew heaps: concrete specification of the operationsSkew heaps: calculation of the merging operationSkew heaps: amortized complexity of the merging operation

6 ConclusionsOur goals?Students’ point of view

34/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Did we reach our goals?

Overall? Yes. ButThe calculation of the merge algorithm is too simple to bereally convincing (however simplicity was one of the aims ofperiod 3)Amortized analysis? debatable, Theory : easy; Practice :requires to be skilled (intuition of Φ)

35/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

B vs EB?

Feature B EB

Data model set theory "inspired" from B

Model of computing state based functional

Number of refinement any one (formal)

Type of refinement relational functional

Induction/recursion In principle yes but... essential (inductive data structures...)but stack oveflows...

Operations "procedures" functions

Tools No (B prover)

Development

"The constructionof a programand its proofs of correctnessshould be so intimateas to make it impossibleto detect which of the twois driving the other"

quite natural

36/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Students’ point of view

A questionnaire:1 General points about the software engineering discipline2 On the EB approach used in the module “data structure”3 Lectures modalities4 Supervised work modalities5 Practicals modalities

37/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

A – How do you define the activity of specifying?

“To prove that a program makes what we ask it to do”“It is a method which allows resolving a problem in aprogressive and effective way”

38/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

B – To your opinion is it useful to specify before programming?

%

Yes 94.44No 5.56

(no) “Waste of time, I specify at the same time as I program”

39/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

C – To your opinion is it useful to specify formally beforeprogramming?

%

Yes 72.22No 27.78

(no) “Formal specifications are more complicated than informalones”(no) “Having experience allows doing without it”

40/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

D – What do you think of the following statement: “softwarecomputing is a scientific discipline”?

%

Yes 83.93No 16.07

(no) “It’s a discipline which requires open-mindedness and asksfor a certain philosophy. It appeals to imagination”“A science in labs, a chaos in the economic environment”“The scientific bases are necessary to develop coherentsoftware which work. Nevertheless I think that many computerspecialists go on and succeed all the same in their job”

41/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

E – Did your opinion on this subject evolve since your arrival inEnssat?

%

Yes 69.64No 30.36

(no) “Nobody managed to convince me of the opposite”

For those who provided the answer yes, their opinion has evolvedfrom “is not a science” to “is a science”

42/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

F – Have you already heard about software called provers?

%

Yes 25.93No 74.07

43/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

General points about the software engineering discipline

G – Did you already use one of them?

%

Yes 7.41No 92.59

44/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

A – Did the approach used in this module surprise you?

%Yes 67.86No 32.14

(yes) “It is a step far from usual which goes against what is usually done”

“I did not think that one could connect math and programming in this manner”

“I’m amazed how quick is the coding stage once the design is achieved”

“Logic but not easy to accept”

“Much more clear than last year” (two year ago)

“I did not thought it was possible to calculate operations”

“How is it used in industry?”

45/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

B – Did the notations used in the module pose any problems toyou?

%

Yes 51.79No 48.21

(Yes) “to have a grip on set notations, at the beginning”(Yes) “they are different from those used in math”(Yes) “too many symbols”

46/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

C – Do you prefer to "guess by intuition" or to calculate programs?

%To guess 50.00To calculate 50.00

(guess) “its easier to think and imagine one or even several solutions”

(guess) “it’s more fun”

(guess) “It’s easier but to be fair I need to practice much more. Moreover asweeping change in the way I think is necessary”

“There should be domains where it fail?!”

(guess) “This is the way I have learned. My personal logic is based on intuition”

(calculate) “A better chance to come across the good solution”...

47/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

D – According to you is it preferable, from the point of view of theconfidence one can have in a program, to "guess it by intuition" itor to calculate it?

%

To guess 9.26To calculate 90.74

(guess) “I prefer to rely on me and on what I know rather thanto rely on calculations which could be unsound”“It depends on the program itself as well as on the person whodevelop it”

48/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

E – Characterize the EB approach for a computer specialist whowould not know it

“Complicated, not very convenient, without much interest ingeneral”

49/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

E – Do you think that this “data structures” module made youprogress in your practice or in your knowledge of softwareengineering?

%

Yes 87.04No 12.96

“No”

50/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

F – If your answer is “Yes”, classify according to their importance,the following features:

position feature average1 A methodology 1.742 A formal method 3.112 Enlarged knowledge of efficient data structures 3.114 A specification language 3.945 A functional approach to programming 4.386 A language for representing operations 4.887 (Another) approach of complexity 5.69

51/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

G – According to you, had you the sufficient prerequisites to followthe module?

%

Yes 85.71No 14.29

(No) Ignorance of the discipline “specification”(No) “Lacuna in set oriented maths”

52/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

On the EB approach used in the module “data structure”

H – Did you use the on-line slides at your disposal?

%

Yes 53.70No 46.30

53/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Modalities: lectures

A – Choice of the fundamental data structures

%

Very satisfying 33.33Correct 62.96Unsatisfying 3.70

54/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Modalities: lectures

B – Choice of the implementation of the fundamental datastructures

%

Very satisfying 40.74Correct 59.26Unsatisfying 0.0

55/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Free expression

“Most of my programs use very few data structures or recursionbecause they are oriented towards the convergence telephony/IPwhere the development is different”

56/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

feed back

From the students: except 2 or 3, quite cheerfull opinionsFrom the teachers’ team:

Don’t want to go back to the previous situationGreat support and fruitful discussions

57/58 Marc Guyomard A Balanced Presentation of Skew Heaps

Introduction: context and goalsEB Method

Amortized complexityAn abstract specification of a priority queue

Implementing priority queues using skew heapsConclusions

Our goals?Students’ point of view

Thanks!

58/58 Marc Guyomard A Balanced Presentation of Skew Heaps