Speed: Precise and Efficient Static Estimation of Program Computational Complexity

Size: px
Start display at page:

Download "Speed: Precise and Efficient Static Estimation of Program Computational Complexity"

Transcription

1 Speed: Precise and Efficient Static Estimation of Program Computational Complexity Sumit Gulwani Krishna K. Mehra Trishul Chilimbi POPL 2009 Presented by Stefan Blumer

2 Motivation

3 Performance Bugs Motivation

4 Motivation Performance Bugs Testing requires writing or generating tests

5 Motivation Performance Bugs Testing requires writing or generating tests Testing doesn't proof absence of performance bugs

6 Motivation Performance Bugs Testing requires writing or generating tests Testing doesn't proof absence of performance bugs Termination Proofers: no information about time complexity of programs

7 Solution

8 Solution Static analysis that returns symbolic complexity bounds for procedures in terms of their input

9 Solution Static analysis that returns symbolic complexity bounds for procedures in terms of their input SPEED: Input: c/c++ programs

10 Solution Static analysis that returns symbolic complexity bounds for procedures in terms of their input SPEED: Input: c/c++ programs Output: symbolic upper bounds on the runtime complexity.

11 How does it work? 1: void square(x, y) { 2: for (i:=0; i<x; i++) { 3: for (j:=0; j<y; j++) { 4: } 5: } 6: }

12 How does it work? Uses program traces 1: void square(x, y) { 2: for (i:=0; i<x; i++) { 3: for (j:=0; j<y; j++) { 4: } 5: } 6: }

13 How does it work? Uses program traces Instrumentation of counter variables to count loop iterations Single counter... 1: void square(x, y) { 2: c0:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c0++; 6: } 7: c0++; 8: } 9: }

14 How does it work? Uses program traces Instrumentation of counter variables to count loop iterations Statically compute an upper bound using an invariant generation tool Single counter... 1: void square(x, y) { 2: c0:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c0++; 6: inv: c0 <= x+x*y; 7: } 8: c0++; 9: } 10: }

15 How does it work? Uses program traces Instrumentation of counter variables to count loop iterations Statically compute an upper bound using an invariant generation tool Single counter... Invariant generation tools can't handle non-linear invariants! 1: void square(x, y) { 2: c0:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c0++; 6: inv: c0 <= x+x*y; 7: } 8: c0++; 9: } 10: }

16 How does it work? Uses program traces Instrumentation of counter variables to count loop iterations Statically compute an upper bound using an invariant generation tool Multiple Counters: 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: } 7: c0++; c1:=0; 8: } 9: } Dependencies between counters Only linear bounds on c0 and c1

17 How does it work? Uses program traces Instrumentation of counter variables to count loop iterations Statically compute an upper bound using an invariant generation tool Multiple Counters: Dependencies between counters Only linear bounds on c0 and c1 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

18 Invariant generation tool

19 Input: Procedure Invariant generation tool

20 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location

21 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location Black Box

22 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location Black Box How efficient?

23 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location Black Box How efficient? Restrictions?

24 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location Black Box How efficient? Restrictions? Implemented using abstract interpretation

25 Input: Procedure Invariant generation tool Output: linear invariants in terms of the procedure input for any program location Black Box How efficient? Restrictions? Implemented using abstract interpretation Non-linear invariant generation isn't feasible

26 Multiple counters 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

27 Multiple counters Each back-edge in the control flow graph must increment one counter 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

28 Multiple counters Each back-edge in the control flow graph must increment one counter Dependencies between counters root 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: } c0 c1

29 Multiple counters Each back-edge in the control flow graph must increment one counter Dependencies between counters No dependency cycles root 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: } c0 c1

30 Multiple counters Each back-edge in the control flow graph must increment one counter Dependencies between counters No dependency cycles Dependent counters are initialized with 0 at back-edges root 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: } c0 c1

31 Proof structure 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

32 Proof structure Let S be a set of counters {c0, c1} 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

33 Proof structure Let S be a set of counters {c0, c1} Let M be a mapping from backedges to counters {(7,c1),(10,c0)} 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

34 Proof structure Let S be a set of counters {c0, c1} Let M be a mapping from backedges to counters {(7,c1),(10,c0)} Let G be a DAG over {(root,c0),(c0,c1)} S {root} 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

35 Proof structure Let S be a set of counters {c0, c1} Let M be a mapping from backedges to counters {(7,c1),(10,c0)} Let G be a DAG over {(root,c0),(c0,c1)} S {root} Let B be a mapping from backedge to some symbolic bound {(7,c1<=y), (10,c0<=x) 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

36 Proof structure Let S be a set of counters {c0, c1} Let M be a mapping from backedges to counters {(7,c1),(10,c0)} Let G be a DAG over {(root,c0),(c0,c1)} S {root} Let B be a mapping from backedge to some symbolic bound {(7,c1<=y), (10,c0<=x)} Tuple (S,M,G,B) is a proofstructure if the invariant generation tool can find a bound for every counter 1: void square(x, y) { 2: c0,c1:=0; 3: for (i:=0; i<x; i++) { 4: for (j:=0; j<y; j++) { 5: c1++; 6: inv: c1<=y 7: } 8: c0++; c1:=0; 9: inv: c0<=x 10: } 11: }

37 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) )

38 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) Make term nonnegative ( 1+ (c', c) G TotalBound (c ' ) )

39 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) The bound of counter c

40 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) Iterate over all predecessors

41 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) TotalBound (c0)= Max(0, x) (1+TotalBound (root))= Max(0, x)

42 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) TotalBound (c0)= Max(0, x) (1+TotalBound (root))= Max(0, x) TotalBound (c1)=max(0, y) (1+TotalBound (c0)) =Max(0, y) (1+Max(0, x))

43 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) TotalBound (c0)= Max(0, x) (1+TotalBound (root))= Max(0, x) TotalBound (c1)=max(0, y) (1+TotalBound (c0)) =Max(0, y) (1+Max(0, x)) U =Max(0, x)+max(0, y) (1+Max(0, x))

44 Computing total bound from proof structure U = c S TotalBound (root)=0 TotalBound (c) TotalBound (c)= Max({0} {B(q) M (q)=c }) ( 1+ (c', c) G TotalBound (c ' ) ) TotalBound (c0)= Max(0, x) (1+TotalBound (root))= Max(0, x) TotalBound (c1)=max(0, y) (1+TotalBound (c0)) =Max(0, y) (1+Max(0, x)) U =Max(0, x)+max(0, y) (1+Max(0, x)) U =x+ y+x y If x, y >= 0

45 How to create a proof structure?

46 How to create a proof structure? How many counters? Which counter where to increment? What dependencies between counters?

47 How to create a proof structure? How many counters? Which counter where to increment? What dependencies between counters? For a procedure, multiple Proof Structures may exist! Different proof-structures may lead to different bounds! Counter dependency doesn't correspond to the loop nesting structure!

48 Optimal proof structure

49 Optimal proof structure Bound is not larger than the bound of any other proof structure

50 Optimal proof structure Bound is not larger than the bound of any other proof structure Check if proof structure is optimal Compare two proof structures Number of Triplets (S, M, G) is exponential in the number of back edges

51 Counter-optimal proof structure

52 Counter-optimal proof structure Heuristic: Minimal number of counters Minimal number of dependencies

53 Counter-optimal proof structure Heuristic: Minimal number of counters Minimal number of dependencies Greedy algorithm: 1) Chose a back edge that has no counter assigned yet 2) Try to assign an existing counter to that back-edge. If it fails, go to 3 otherwise got to 1 3) Add new counter, and make it depend on all other counters. If it fails, go to 1 otherwise go to 4 4) Remove dependencies as long as possible. Go to 1.

54 How to handle data structures 1: void worklist(list<t> l) { 2: c0 := 0; 3: while (!l.empty()) { 4: l.pop_back(); 5: c0++; 6: inv: c0<=old(size(l)); 4: } 5: }

55 How to handle data structures Quantitative functions over data structures 1: void worklist(list<t> l) { 2: c0 := 0; 3: while (!l.empty()) { 4: l.pop_back(); 5: c0++; 6: inv: c0<=old(size(l)); 4: } 5: }

56 How to handle data structures Quantitative functions over data structures No need for heap shape analysis 1: void worklist(list<t> l) { 2: c0 := 0; 3: while (!l.empty()) { 4: l.pop_back(); 5: c0++; 6: inv: c0<=old(size(l)); 4: } 5: }

57 How to handle data structures Quantitative functions over data structures No need for heap shape analysis Provide quantitative information like: size of a list, current position of an iterator 1: void worklist(list<t> l) { 2: c0 := 0; 3: while (!l.empty()) { 4: l.pop_back(); 5: c0++; 6: inv: c0<=old(size(l)); 4: } 5: }

58 How to handle data structures Quantitative functions over data structures No need for heap shape analysis Provide quantitative information like: size of a list, current position of an iterator Programmer has to define for each procedure of the data structure, how it affects the value of the quantitative function 1: void worklist(list<t> l) { 2: c0 := 0; 3: while (!l.empty()) { 4: l.pop_back(); 5: c0++; 6: inv: c0<=old(size(l)); 4: } 5: }

59 How to handle data structures 1: class List<T> { 2: bool empty() { 3: ensures 4: size(this) = old(size(this)); 5: } 6: 7: void pop_back() { 8: ensures 9: size(this) = old(size(this))-1; 10: } 11: 12: void clear() { 13: ensures size(this) = 0; 14: } 15: }

60 How to handle data structures methods: empty() pop_back() clear() 1: class List<T> { 2: bool empty() { 3: ensures 4: size(this) = old(size(this)); 5: } 6: 7: void pop_back() { 8: ensures 9: size(this) = old(size(this))-1; 10: } 11: 12: void clear() { 13: ensures size(this) = 0; 14: } 15: }

61 How to handle data structures methods: empty() pop_back() clear() Quantitative function: size(list) 1: class List<T> { 2: bool empty() { 3: ensures 4: size(this) = old(size(this)); 5: } 6: 7: void pop_back() { 8: ensures 9: size(this) = old(size(this))-1; 10: } 11: 12: void clear() { 13: ensures size(this) = 0; 14: } 15: }

62 How to handle data structures methods: empty() pop_back() clear() Quantitative function: size(list) Programmer must make sure to get the semantics right! 1: class List<T> { 2: bool empty() { 3: ensures 4: size(this) = old(size(this)); 5: } 6: 7: void pop_back() { 8: ensures 9: size(this) = old(size(this))-1; 10: } 11: 12: void clear() { 13: ensures size(this) = 0; 14: } 15: }

63 How to handle procedure calls Non-recursive procedure call: 1: void foo(x) { 2: c0 := 0; 3: for (i:=0; i<x; i++) { 4: inv: i<x; 5: bar(i); 6: c0++; 7: inv: c0<=x; 8: } 9: }

64 How to handle procedure calls Non-recursive procedure call: First compute symbolic bounds of procedure bar(x) 1: void foo(x) { 2: c0 := 0; 3: for (i:=0; i<x; i++) { 4: inv: i<x; 5: bar(i); 6: c0++; 7: inv: c0<=x; 8: } 9: }

65 How to handle procedure calls Non-recursive procedure call: First compute symbolic bounds of procedure bar(x) Compute bounds on argument i in terms of input parameter x 1: void foo(x) { 2: c0 := 0; 3: for (i:=0; i<x; i++) { 4: inv: i<x; 5: bar(i); 6: c0++; 7: inv: c0<=x; 8: } 9: }

66 How to handle procedure calls Non-recursive procedure call: First compute symbolic bounds of procedure bar(x) Compute bounds on argument i in terms of input parameter x Multiply bound on call complexity with the bound on statement execution count 1: void foo(x) { 2: c0 := 0; 3: for (i:=0; i<x; i++) { 4: inv: i<x; 5: bar(i); 6: c0++; 7: inv: c0<=x; 8: } 9: }

67 How to handle procedure calls Non-recursive procedure call: First compute symbolic bounds of procedure bar(x) Compute bounds on argument i in terms of input parameter x Multiply bound on call complexity with the bound on statement execution count Bounds on call arguments limited to linear bounds! 1: void foo(x) { 2: c0 := 0; 3: for (i:=0; i<x; i++) { 4: inv: i<x; 5: bar(i); 6: c0++; 7: inv: c0<=x; 8: } 9: }

68 How to handle procedure calls Recursive procedure call: 1: void foo(x) { 2: if (x>0) { 3: foo(x-1); 4: } 5: }

69 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

70 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

71 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables Initializes single global counter 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

72 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables Initializes single global counter Calls actual procedure foo(x) 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

73 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables Initializes single global counter Calls actual procedure foo(x) Increment counter before call 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

74 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables Initializes single global counter Calls actual procedure foo(x) Increment counter before call Compute bound for c0 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

75 How to handle procedure calls Recursive procedure call: Generate a procedure foo'(x): Stores parameters to global variables Initializes single global counter Calls actual procedure foo(x) Increment counter before call Compute bound for c0 Single global counter restricts to linear bounds of recursion! 1: void foo(x) { 2: if (x>0) { 3: c0++; 4: foo(x-1); 5: inv: c0 <= x' 6: } 7: } 8: 9: int c0; 10: int x'; 11: 12: void foo'(x) { 13: x':= x; c0 := 0; 14: foo(x); 15: }

76 Results of SPEED

77 Results of SPEED Tested on parts of c++ std and Microsoft products

78 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops

79 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops Able to get correct linear bounds on procedures with a nesting depth of up to 5

80 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops Able to get correct linear bounds on procedures with a nesting depth of up to 5 Most failures because of:

81 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops Able to get correct linear bounds on procedures with a nesting depth of up to 5 Most failures because of: Bounds depend on environment assumptions: class invariants, preconditions, concurrency and os-call properties

82 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops Able to get correct linear bounds on procedures with a nesting depth of up to 5 Most failures because of: Bounds depend on environment assumptions: class invariants, preconditions, concurrency and os-call properties Generation of bounds requires path sensitive invariant generation if (p) x++; else x--;

83 Results of SPEED Tested on parts of c++ std and Microsoft products Successful creation of bounds for more than half of the tested loops Able to get correct linear bounds on procedures with a nesting depth of up to 5 Most failures because of: Bounds depend on environment assumptions: class invariants, preconditions, concurrency and os-call properties Generation of bounds requires path sensitive invariant generation if (p) x++; else x--; Integrated into the code check-in process of some Microsoft product groups

84 Conclusion

85 Conclusion Everything built on the linear invariant generation tool

86 Conclusion Everything built on the linear invariant generation tool Black box, no guaranties

87 Conclusion Everything built on the linear invariant generation tool Black box, no guaranties Elegant solution with multiple counters

88 Conclusion Everything built on the linear invariant generation tool Black box, no guaranties Elegant solution with multiple counters Very limiting on procedure calls and recursion

89 Conclusion Everything built on the linear invariant generation tool Black box, no guaranties Elegant solution with multiple counters Very limiting on procedure calls and recursion Will be obsolete when non-linear invariant generators appear

90 Conclusion Everything built on the linear invariant generation tool Black box, no guaranties Elegant solution with multiple counters Very limiting on procedure calls and recursion Will be obsolete when non-linear invariant generators appear Few and intransparent results

91 Questions?

SPEED: precise and efficient static estimation of program computational complexity

SPEED: precise and efficient static estimation of program computational complexity SPEED: precise and efficient static estimation of program computational complexity Andrey Breslav report on a paper by S. Gulwani, K. Mehra and T. Chilimbi University of Tartu 2010 Outline Linear Invariant

More information

Static verification of program running time

Static verification of program running time Static verification of program running time CIS 673 course project report Caleb Stanford December 2016 Contents 1 Introduction 2 1.1 Total Correctness is Not Enough.................................. 2

More information

SPEED: Precise and Efficient Static Estimation of Program Computational Complexity

SPEED: Precise and Efficient Static Estimation of Program Computational Complexity SPEED: Precise and Efficient Static Estimation of Program Computational Complexity Sumit Gulwani Microsoft Research sumitg@microsoft.com Krishna K. Mehra Microsoft Research India kmehra@microsoft.com Trishul

More information

The Cilk part is a small set of linguistic extensions to C/C++ to support fork-join parallelism. (The Plus part supports vector parallelism.

The Cilk part is a small set of linguistic extensions to C/C++ to support fork-join parallelism. (The Plus part supports vector parallelism. Cilk Plus The Cilk part is a small set of linguistic extensions to C/C++ to support fork-join parallelism. (The Plus part supports vector parallelism.) Developed originally by Cilk Arts, an MIT spinoff,

More information

Measuring Efficiency

Measuring Efficiency Growth Announcements Measuring Efficiency Recursive Computation of the Fibonacci Sequence Our first example of tree recursion: fib(3) fib(5) fib(4) def fib(n): if n == 0: return 0 elif n == 1: return 1

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved. Chapter 13 Recursion Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Recursive void Functions Tracing recursive calls Infinite recursion, overflows Recursive Functions that Return

More information

Mathematical Induction

Mathematical Induction Mathematical Induction Victor Adamchik Fall of 2005 Lecture 3 (out of three) Plan 1. Recursive Definitions 2. Recursively Defined Sets 3. Program Correctness Recursive Definitions Sometimes it is easier

More information

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of

More information

Cilk, Matrix Multiplication, and Sorting

Cilk, Matrix Multiplication, and Sorting 6.895 Theory of Parallel Systems Lecture 2 Lecturer: Charles Leiserson Cilk, Matrix Multiplication, and Sorting Lecture Summary 1. Parallel Processing With Cilk This section provides a brief introduction

More information

SORTING. Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity

SORTING. Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity 1 SORTING Insertion sort Selection sort Quicksort Mergesort And their asymptotic time complexity See lecture notes page, row in table for this lecture, for file searchsortalgorithms.zip Lecture 11 CS2110

More information

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

More information

Compilers. Cool Semantics II. Alex Aiken

Compilers. Cool Semantics II. Alex Aiken Compilers Informal semantics of new T Allocate locations to hold all attributes of an object of class T Essentially, allocate a new object Set attributes with their default values Evaluate the initializers

More information

CSC 222: Computer Programming II. Spring 2004

CSC 222: Computer Programming II. Spring 2004 CSC 222: Computer Programming II Spring 2004 Stacks and recursion stack ADT push, pop, top, empty, size vector-based implementation, library application: parenthesis/delimiter matching run-time

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination ECE 25 Data Structures and Algorithms University of Waterloo Department of Electrical and Computer Engineering ECE 25 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides:

More information

Using Build-Integrated Static Checking to Preserve Correctness Invariants

Using Build-Integrated Static Checking to Preserve Correctness Invariants Using Build-Integrated Static Checking to Preserve Correctness Invariants Hao Chen University of California, Davis Jonathan Shapiro Johns Hopkins University Motivation A key problem in creating secure

More information

Runtime Checking for Program Verification Systems

Runtime Checking for Program Verification Systems Runtime Checking for Program Verification Systems Karen Zee, Viktor Kuncak, and Martin Rinard MIT CSAIL Tuesday, March 13, 2007 Workshop on Runtime Verification 1 Background Jahob program verification

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Summer Term 2015 Dr. Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 State: May 6, 2015 Betriebssysteme / verteilte Systeme

More information

Tail Recursion. ;; a recursive program for factorial (define fact (lambda (m) ;; m is non-negative (if (= m 0) 1 (* m (fact (- m 1))))))

Tail Recursion. ;; a recursive program for factorial (define fact (lambda (m) ;; m is non-negative (if (= m 0) 1 (* m (fact (- m 1)))))) Tail Recursion 1 Tail Recursion In place of loops, in a functional language one employs recursive definitions of functions. It is often easy to write such definitions, given a problem statement. Unfortunately,

More information

Name: CIS 341 Final Examination 10 December 2008

Name: CIS 341 Final Examination 10 December 2008 Name: CIS 341 Final Examination 10 December 2008 1 /8 2 /12 3 /18 4 /18 5 /14 Total /70 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 11 pages

More information

Chapter 1. Fundamentals of Higher Order Programming

Chapter 1. Fundamentals of Higher Order Programming Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

More information

Contract Programming For C++0x

Contract Programming For C++0x Contract Programming For C++0x WG21/N1800 and J16/05-0060 Lawrence Crowl and Thorsten Ottosen lawrence.crowl@sun.com and nesotto@cs.aau.dk 2005-04-27 Overview This is an annotated version of the presentation

More information

Algorithm Analysis. Jordi Cortadella and Jordi Petit Department of Computer Science

Algorithm Analysis. Jordi Cortadella and Jordi Petit Department of Computer Science Algorithm Analysis Jordi Cortadella and Jordi Petit Department of Computer Science What do we expect from an algorithm? Correct Easy to understand Easy to implement Efficient: Every algorithm requires

More information

Shared-memory Parallel Programming with Cilk Plus

Shared-memory Parallel Programming with Cilk Plus Shared-memory Parallel Programming with Cilk Plus John Mellor-Crummey Department of Computer Science Rice University johnmc@rice.edu COMP 422/534 Lecture 4 30 August 2018 Outline for Today Threaded programming

More information

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology The Spin Model Checker : Part I Copyright 2008 CS655 System Korea Advanced Institute of Science and Technology System Spec. In Promela Req. Spec. In LTL Overview of the Spin Architecture Spin Model pan.c

More information

Hoare Logic: Proving Programs Correct

Hoare Logic: Proving Programs Correct Hoare Logic: Proving Programs Correct 17-654/17-765 Analysis of Software Artifacts Jonathan Aldrich Reading: C.A.R. Hoare, An Axiomatic Basis for Computer Programming Some presentation ideas from a lecture

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Local Verification of Global Invariants in

Local Verification of Global Invariants in Local Verification of Global Invariants in 1 Local Verification of Global Invariants in Concurrent Programs Ernie Cohen 1, Michal Moskal 2, Wolfram Schulte 2, Stephan Tobies 1 1 European Microsoft Innovation

More information

Recitation 9. Prelim Review

Recitation 9. Prelim Review Recitation 9 Prelim Review 1 Heaps 2 Review: Binary heap min heap 1 2 99 4 3 PriorityQueue Maintains max or min of collection (no duplicates) Follows heap order invariant at every level Always balanced!

More information

FreePascal changes: user documentation

FreePascal changes: user documentation FreePascal changes: user documentation Table of Contents Jochem Berndsen February 2007 1Introduction...1 2Accepted syntax...2 Declarations...2 Statements...3 Class invariants...3 3Semantics...3 Definitions,

More information

Discrete planning (an introduction)

Discrete planning (an introduction) Sistemi Intelligenti Corso di Laurea in Informatica, A.A. 2017-2018 Università degli Studi di Milano Discrete planning (an introduction) Nicola Basilico Dipartimento di Informatica Via Comelico 39/41-20135

More information

Static Program Analysis Part 1 the TIP language

Static Program Analysis Part 1 the TIP language Static Program Analysis Part 1 the TIP language http://cs.au.dk/~amoeller/spa/ Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Questions about programs Does the program terminate

More information

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211 Objectives Review implementation of Stable Matching Survey of common running times Turn in completed problem sets Jan 18, 2019 Sprenkle - CSCI211 1 Review: Asymptotic Analysis of Gale-Shapley Alg Not explicitly

More information

CS 315 Programming Languages Subprograms

CS 315 Programming Languages Subprograms CS 315 Programming Languages Subprograms Subprograms Definition header: name, parameters (formals), return type body: code E.g.: int triple (int x) return 3 * x; Call name, parameters (actuals) E.g.: triple(3)

More information

Reference Counting. Reference counting: a way to know whether a record has other users

Reference Counting. Reference counting: a way to know whether a record has other users Garbage Collection Today: various garbage collection strategies; basic ideas: Allocate until we run out of space; then try to free stuff Invariant: only the PL implementation (runtime system) knows about

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides: none 14 pages Final Examination

More information

Lecture Notes: Hoare Logic

Lecture Notes: Hoare Logic Lecture Notes: Hoare Logic 17-654/17-754: Analysis of Software Artifacts Jonathan Aldrich (jonathan.aldrich@cs.cmu.edu) Lecture 3 1 Hoare Logic The goal of Hoare logic is to provide a formal system for

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Points off Total off Net Score. CS 314 Final Exam Spring 2016 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

2

2 Trees 1 2 Searching 3 Suppose we want to search for things in a list One possibility is to keep the items in a 'randomly' ordered list, so insertion is O(1), but then a search takes O(n) time Or, we could

More information

CMSC 330: Organization of Programming Languages. Operational Semantics

CMSC 330: Organization of Programming Languages. Operational Semantics CMSC 330: Organization of Programming Languages Operational Semantics Notes about Project 4, Parts 1 & 2 Still due today (7/2) Will not be graded until 7/11 (along with Part 3) You are strongly encouraged

More information

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

Priority Queues and Huffman Trees

Priority Queues and Huffman Trees Priority Queues and Huffman Trees 1 the Heap storing the heap with a vector deleting from the heap 2 Binary Search Trees sorting integer numbers deleting from a binary search tree 3 Huffman Trees encoding

More information

CS314 Final - Spring Suggested Solution and Criteria 1

CS314 Final - Spring Suggested Solution and Criteria 1 CS314 Spring 2017 Final Exam Solution and Grading Criteria. Grading acronyms: AIOBE - Array Index out of Bounds Exception may occur BOD - Benefit of the Doubt. Not certain code works, but, can't prove

More information

Recursive Definitions

Recursive Definitions Recursion Objectives Explain the underlying concepts of recursion Examine recursive methods and unravel their processing steps Explain when recursion should and should not be used Demonstrate the use of

More information

Midterm 2 Exam Principles of Imperative Computation. Tuesday 31 st March, This exam is closed-book with one sheet of notes permitted.

Midterm 2 Exam Principles of Imperative Computation. Tuesday 31 st March, This exam is closed-book with one sheet of notes permitted. Midterm 2 Exam 15-122 Principles of Imperative Computation Tuesday 31 st March, 2015 Name: Andrew ID: Recitation Section: Instructions This exam is closed-book with one sheet of notes permitted. You have

More information

Practice Problems for the Final

Practice Problems for the Final ECE-250 Algorithms and Data Structures (Winter 2012) Practice Problems for the Final Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each

More information

Garbage Collection. Lecture Compilers SS Dr.-Ing. Ina Schaefer. Software Technology Group TU Kaiserslautern. Ina Schaefer Garbage Collection 1

Garbage Collection. Lecture Compilers SS Dr.-Ing. Ina Schaefer. Software Technology Group TU Kaiserslautern. Ina Schaefer Garbage Collection 1 Garbage Collection Lecture Compilers SS 2009 Dr.-Ing. Ina Schaefer Software Technology Group TU Kaiserslautern Ina Schaefer Garbage Collection 1 Content of Lecture 1. Introduction: Overview and Motivation

More information

The Hack programming language:

The Hack programming language: The Hack programming language: Types for PHP Andrew Kennedy Facebook Facebook s PHP Codebase 350,000 files >10,000,000 LoC (www.facebook.com & internally) 1000s of commits per day, 2 releases per day Anecdotally,

More information

Data Structures and Algorithms (DSA) Course 5 Lists. Iulian Năstac

Data Structures and Algorithms (DSA) Course 5 Lists. Iulian Năstac Data Structures and Algorithms (DSA) Course 5 Lists Iulian Năstac Cap. Lists (recapitulation) 1. Introduction Linked lists are the best and simplest example of a dynamic data structure that uses pointers

More information

CORRECTNESS ISSUES AND LOOP INVARIANTS

CORRECTNESS ISSUES AND LOOP INVARIANTS Aout A2 and feedack. Recursion 2 CORRECTNESS ISSUES AND LOOP INVARIANTS S2 has een graded. If you got 30/30, you will proaly have no feedack. If you got less than full credit, there should e feedack showing

More information

"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING

Organizing is what you do before you do something, so that when you do it, it is not all mixed up. ~ A. A. Milne SORTING "Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Fall 2017 Announcements 2 is a program with a teach anything,

More information

Plan of the lecture. Quick-Sort. Partition of lists (or using extra workspace) Quick-Sort ( 10.2) Quick-Sort Tree. Partitioning arrays

Plan of the lecture. Quick-Sort. Partition of lists (or using extra workspace) Quick-Sort ( 10.2) Quick-Sort Tree. Partitioning arrays Plan of the lecture Quick-sort Lower bounds on comparison sorting Correctness of programs (loop invariants) Quick-Sort 7 4 9 6 2 2 4 6 7 9 4 2 2 4 7 9 7 9 2 2 9 9 Lecture 16 1 Lecture 16 2 Quick-Sort (

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 07 Single-Source Shortest Paths (Chapter 24) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/36 Introduction

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures 9//207 ITEC2620 Introduction to Data Structures Lecture b Recursion and Binary Tree Operations Divide and Conquer Break a problem into smaller subproblems that are easier to solve What happens when the

More information

Lecture 18 Restoring Invariants

Lecture 18 Restoring Invariants Lecture 18 Restoring Invariants 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In this lecture we will implement heaps and operations on them. The theme of this lecture is reasoning

More information

CSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session

CSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session CSE 146 Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session Comparing Algorithms Rough Estimate Ignores Details Or really: independent of details What are some details

More information

C Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

C Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff C Programming Language 1 C C is better to use than assembly for embedded systems programming. You can program at a higher level of logic than in assembly, so programs are shorter and easier to understand.

More information

Lecture Notes on Priority Queues

Lecture Notes on Priority Queues Lecture Notes on Priority Queues 15-122: Principles of Imperative Computation Frank Pfenning Lecture 16 October 18, 2012 1 Introduction In this lecture we will look at priority queues as an abstract type

More information

Intro. Speed V Growth

Intro. Speed V Growth Intro Good code is two things. It's elegant, and it's fast. In other words, we got a need for speed. We want to find out what's fast, what's slow, and what we can optimize. First, we'll take a tour of

More information

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Symbolic and Concolic Execution of Programs

Symbolic and Concolic Execution of Programs Symbolic and Concolic Execution of Programs Information Security, CS 526 Omar Chowdhury 10/7/2015 Information Security, CS 526 1 Reading for this lecture Symbolic execution and program testing - James

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming

More information

CS 403/534 Distributed Systems Midterm April 29, 2004

CS 403/534 Distributed Systems Midterm April 29, 2004 CS 403/534 Distributed Systems Midterm April 9, 004 3 4 5 Total Name: ID: Notes: ) Please answer the questions in the provided space after each question. ) Duration is 0 minutes 3) Closed books and closed

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

12/30/2013 S. NALINI,AP/CSE

12/30/2013 S. NALINI,AP/CSE 12/30/2013 S. NALINI,AP/CSE 1 UNIT I ITERATIVE AND RECURSIVE ALGORITHMS Iterative Algorithms: Measures of Progress and Loop Invariants-Paradigm Shift: Sequence of Actions versus Sequence of Assertions-

More information

Automatic Software Verification

Automatic Software Verification Automatic Software Verification Instructor: Mooly Sagiv TA: Oded Padon Slides from Eran Yahav and the Noun Project, Wikipedia Course Requirements Summarize one lecture 10% one lecture notes 45% homework

More information

The Spin Model Checker : Part I/II

The Spin Model Checker : Part I/II The Spin Model Checker : Part I/II Moonzoo Kim CS Dept. KAIST Korea Advanced Institute of Science and Technology Motivation: Tragic Accidents Caused by SW Bugs 2 Cost of Software Errors June 2002 Software

More information

CS 161 Computer Security

CS 161 Computer Security Wagner Spring 2014 CS 161 Computer Security 1/27 Reasoning About Code Often functions make certain assumptions about their arguments, and it is the caller s responsibility to make sure those assumptions

More information

"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING

Organizing is what you do before you do something, so that when you do it, it is not all mixed up. ~ A. A. Milne SORTING "Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne SORTING Lecture 11 CS2110 Fall 2017 Prelim 1 2 It's on Tuesday Evening (3/13) Two Sessions:

More information

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY Lecture 10 CS2110 Fall 2016 Miscellaneous 2 A3 due Monday night. Group early! Only 325 views of the piazza A3 FAQ yesterday morning. Everyone should

More information

Calvin Lin The University of Texas at Austin

Calvin Lin The University of Texas at Austin Interprocedural Analysis Last time Introduction to alias analysis Today Interprocedural analysis March 4, 2015 Interprocedural Analysis 1 Motivation Procedural abstraction Cornerstone of programming Introduces

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

More information

COMP 202 Recursion. CONTENTS: Recursion. COMP Recursion 1

COMP 202 Recursion. CONTENTS: Recursion. COMP Recursion 1 COMP 202 Recursion CONTENTS: Recursion COMP 202 - Recursion 1 Recursive Thinking A recursive definition is one which uses the word or concept being defined in the definition itself COMP 202 - Recursion

More information

Formal Specification and Verification

Formal Specification and Verification Formal Specification and Verification Introduction to Promela Bernhard Beckert Based on a lecture by Wolfgang Ahrendt and Reiner Hähnle at Chalmers University, Göteborg Formal Specification and Verification:

More information

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B. CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function

More information

Simplifying Loop Invariant Generation Using Splitter Predicates. Rahul Sharma Işil Dillig, Thomas Dillig, and Alex Aiken Stanford University

Simplifying Loop Invariant Generation Using Splitter Predicates. Rahul Sharma Işil Dillig, Thomas Dillig, and Alex Aiken Stanford University Simplifying Loop Invariant Generation Using Splitter Predicates Rahul Sharma Işil Dillig, Thomas Dillig, and Alex Aiken Stanford University Loops and Loop Invariants Loop Head x = 0; while( x

More information

Finite Math Linear Programming 1 May / 7

Finite Math Linear Programming 1 May / 7 Linear Programming Finite Math 1 May 2017 Finite Math Linear Programming 1 May 2017 1 / 7 General Description of Linear Programming Finite Math Linear Programming 1 May 2017 2 / 7 General Description of

More information

CISC 320 Midterm Exam

CISC 320 Midterm Exam Name: CISC 320 Midterm Exam Wednesday, Mar 25, 2015 There are 19 questions. The first 15 questions count 4 points each. For the others, points are individually shown. The total is 100 points. Multiple

More information

Interprocedural Analysis. Motivation. Interprocedural Analysis. Function Calls and Pointers

Interprocedural Analysis. Motivation. Interprocedural Analysis. Function Calls and Pointers Interprocedural Analysis Motivation Last time Introduction to alias analysis Today Interprocedural analysis Procedural abstraction Cornerstone of programming Introduces barriers to analysis Example x =

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10 Recursion and Search MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to

More information

We cover recursion in 150. Why do it again in 151?

We cover recursion in 150. Why do it again in 151? Recursion We cover recursion in 150. Why do it again in 151? First, good solutions to problems are often recursive. Here is a quick way to sort a list of objects: split the list in half, recursively sort

More information

16 Greedy Algorithms

16 Greedy Algorithms 16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices

More information

Backward Reasoning: Rule for Assignment. Backward Reasoning: Rule for Sequence. Simple Example. Hoare Logic, continued Reasoning About Loops

Backward Reasoning: Rule for Assignment. Backward Reasoning: Rule for Sequence. Simple Example. Hoare Logic, continued Reasoning About Loops Backward Reasoning: Rule for Assignment Hoare Logic, continued Reasoning About Loops { wp( x=expression,q) x = expression; { Q Rule: the weakest precondition wp( x=expression,q) is Q with all occurrences

More information

Mock exam 1. ETH Zurich. Date: 9./10. November 2009

Mock exam 1. ETH Zurich. Date: 9./10. November 2009 Mock exam 1 ETH Zurich Date: 9./10. November 2009 Name: Group: 1 Terminology (8 points) Put checkmarks in the checkboxes corresponding to the correct answers. Multiple correct answers are possible; there

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Shared-memory Parallel Programming with Cilk Plus

Shared-memory Parallel Programming with Cilk Plus Shared-memory Parallel Programming with Cilk Plus John Mellor-Crummey Department of Computer Science Rice University johnmc@rice.edu COMP 422/534 Lecture 4 19 January 2017 Outline for Today Threaded programming

More information

The SPIN Model Checker

The SPIN Model Checker The SPIN Model Checker Metodi di Verifica del Software Andrea Corradini Lezione 1 2013 Slides liberamente adattate da Logic Model Checking, per gentile concessione di Gerard J. Holzmann http://spinroot.com/spin/doc/course/

More information

Review: Hoare Logic Rules

Review: Hoare Logic Rules Review: Hoare Logic Rules wp(x := E, P) = [E/x] P wp(s;t, Q) = wp(s, wp(t, Q)) wp(if B then S else T, Q) = B wp(s,q) && B wp(t,q) Proving loops correct First consider partial correctness The loop may not

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

CSCI 103 More Recursion & Generating All Combinations. Mark Redekopp

CSCI 103 More Recursion & Generating All Combinations. Mark Redekopp 1 CSCI 103 More Recursion & Generating All Combinations Mark Redekopp 2 Get Some Code In your VM create a new folder and cd into it mkdir ffill cd ffill wget http://ee.usc.edu/~redekopp/cs103/floodfill.tar

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Reasoning about programs

Reasoning about programs Reasoning about programs Last time Coming up This Thursday, Nov 30: 4 th in-class exercise sign up for group on moodle bring laptop to class Final projects: final project presentations: Tue Dec 12, in

More information

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise Last time Reasoning about programs Coming up This Thursday, Nov 30: 4 th in-class exercise sign up for group on moodle bring laptop to class Final projects: final project presentations: Tue Dec 12, in

More information