CS 15-122: Principles of Imperative Programming
(Fall 2017)

Schedule of Classes

At a glance ...

August 2017
UMTWRFS
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
September 2017
UMTWRFS
     12
3456789
10111213141516
17181920212223
24252627282930
       
October 2017
UMTWRFS
1234567
891011121314
15161718192021
22232425262728
293031    
       
November 2017
UMTWRFS
   1234
567891011
12131415161718
19202122232425
2627282930  
       
December 2017
UMTWRFS
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Outline[+]


Mon 28 Aug
Lab 1
Setup
This lab practices using Linux and running the C0 interpreter and compiler.
Tue 29 Aug
Lecture 1
Welcome and Course Introduction
We outline the course, its goals, and talk about various administrative issues.

A mysterious function ...
We examine a program we know nothing about, making hypotheses about what it is supposed to do. We notice that this function has no meaningful output for some inputs, which leads us to restricting its valid inputs using preconditions. We use a similar mechanism, postconditions, to describe the value it returns. Along the way, we get acquainted to C0 and its support for checking pre- and post-conditions. We then notice that this function doesn't return the expected outputs even for some valid inputs ...
Concepts:
  • Pre- and post-conditions
  • Testing
  • Contract support in C0
Readings:
Thu 31 Aug
Lecture 2
Contracts
Contracts are program annotations that spell out what the code is supposed to do. They are the key to connecting algorithmic ideas to their implementation as a program. In this lecture, we illustrate the use of contracts by means of a simple C0 program. As we do so, we learn to verify loop invariants — an important type of contract, we see how contracts can help us write correct code, and we get acquainted with C0's automated support to validating contracts.
Concepts:
  • Loop invariants
  • Assertions
  • Using contracts to write correct programs
  • Contract support in C0
Fri 1 Sep
Recitation 1
C0 Basics
This recitation reviews elementary C0 constructs and practices reasoning about code.
Mon 4 Sep
No class (Labor Day)
Tue 5 Sep
Lecture 3
Ints
In this lecture, we explore how number representation interplays with the the ability to write effective contracts. We focus on integers and see how the binary representation called two's complement supports the laws of modular arithmetic, which C0 embraces. We also examine operations that allow exploiting the bit pattern of a binary number to achieve compact representations of other entities of interest, and to manipulate them.
  • Representation of integers
  • Two's complement
  • Modular arithmetic
  • Bit-level operations
Thu 7 Sep
Lecture 4
Arrays
In this lecture, we examine arrays as our first composite data structure, i.e., a data construction designed to hold multiple values, together with operations to access them. Accessing an array element outside of its range is undefined — it is a safety violation — and we see how to use contracts, in particular loop invariants, to ensure the safety of array accesses in a program. Arrays are stored in memory, which means that they are manipulated through an address. This raises the possibility of aliasing, a notorious source of bugs in carelessly written programs.
  • Arrays
  • Memory allocation
  • Safe access
  • Loop invariants for arrays
  • Aliasing
Fri 8 Sep
Recitation 2
A Bit about Bytes
This recitation practices base conversion and writing code that manipulates bits.
Mon 11 Sep
Lab 2
A Reversal of Fortune
This lab practices working with bitwise operations on integers and with arrays.
Tue 12 Sep
Lecture 5
Searching Arrays
We practice reasoning about arrays by implementing a function that searches whether an array contains a given value — this is the gateway to a whole class of useful operations. We notice that this function returns its result more quickly when the array is sorted. We write a specialized variant that assumes that the array is sorted, and show that it works correctly by reasoning about array bounds. The first (simpler but less efficient) version acts as a specification for the the second (slightly more complex but often faster). Using the specification in the contract for the implementation is a standard technique to help writing correct code.
  • Linear search
  • Reasoning about arrays
  • Sorted arrays
  • Performance as number of operations executed
  • Specification vs. implementation
Thu 14 Sep
Lecture 6
Sorting Arrays
We examine big-O notation as a mathematical tool to describe the running time of algorithms, especially for the purpose of comparing two algorithms that solve the same problem. As a case study, we use the problem of sorting an array, and for now a single sorting algorithm, selection sort. As we implement selection sort, we see that starting with contracts gives us high confidence that the resulting code will work correctly. Along the way, we develop a useful library of functions about sorted arrays to be used in contracts.
  • Big-O notation
  • Selection sort
  • Deliberate programming
  • Asymptotic complexity analysis
Fri 15 Sep
Recitation 3
Function Family Reunion
This recitation practices understanding and using big-O notation.
Mon 18 Sep
Lab 3
Time of Your Life
This lab practices testing and timing running code to estimate its complexity.
Tue 19 Sep
Lecture 7
Binary search
When searching for a value in a sorted array, examining the middle element allows us to discard half of the array in the worst case. The resulting algorithm, binary search, has logarithmic complexity which is much better than linear search (which is linear). Achieving a correct imperative implementation can be tricky however, and we use once more contracts as a mechanism to reach this goal.
  • Binary search
  • Divide-and-conquer
  • Deliberate implementation
  • Checking complex loop invariants
Thu 21 Sep
Lecture 8
waiting on id lecture8...
Fri 22 Sep
Recitation 4
waiting on id recitation4...
Mon 25 Sep
Lab 4
waiting on id lab4...
Tue 26 Sep
Lecture 9
waiting on id lecture9...
Thu 28 Sep
Lecture 10
waiting on id lecture10...
Fri 29 Sep
Recitation 5
waiting on id recitation5...
Mon 2 Oct
Lab 5
waiting on id lab5...
Tue 3 Oct
Lecture 11
waiting on id lecture11...
Thu 5 Oct
Midterm 1
waiting on id e1...
Fri 6 Oct
Recitation 6
waiting on id recitation6...
Mon 9 Oct
Lab 6
waiting on id lab6...
Tue 10 Oct
Lecture 12
waiting on id lecture12...
Thu 12 Oct
Lecture 13
waiting on id lecture13...
Fri 13 Oct
Recitation 7
waiting on id recitation7...
Mon 16 Oct
Lab 7
waiting on id lab7...
Tue 17 Oct
Lecture 14
waiting on id lecture14...
Thu 19 Oct
Lecture 15
waiting on id lecture15...
Fri 20 Oct
waiting on id h2...
Mon 23 Oct
Lab 8
waiting on id lab8...
Tue 24 Oct
Lecture 16
waiting on id lecture16...
Thu 26 Oct
Lecture 17
waiting on id lecture17...
Fri 27 Oct
Recitation 8
waiting on id recitation8...
Mon 30 Oct
Lab 9
waiting on id lab9...
Tue 31 Oct
Lecture 18
waiting on id lecture18...
Thu 2 Nov
Lecture 19
waiting on id lecture19...
Fri 3 Nov
Recitation 9
waiting on id recitation9...
Mon 6 Nov
Lab 10
waiting on id lab10...
Tue 7 Nov
Lecture 20
waiting on id lecture20...
Thu 9 Nov
Midterm 2
waiting on id e2...
Fri 10 Nov
Recitation 10
waiting on id recitation10...
Mon 13 Nov
Lab 11
waiting on id lab11...
Tue 14 Nov
Lecture 21
waiting on id lecture21...
Thu 16 Nov
Lecture 22
waiting on id lecture22...
Fri 17 Nov
Recitation 11
waiting on id recitation11...
Mon 20 Nov
Lab 12
waiting on id lab12...
Tue 21 Nov
Lecture 23
waiting on id lecture23...
Thu 23 Nov
waiting on id h3...
Fri 24 Nov
waiting on id h4...
Mon 27 Nov
Lab 13
waiting on id lab13...
Tue 28 Nov
Lecture 24
waiting on id lecture24...
Thu 30 Nov
Lecture 25
waiting on id lecture25...
Fri 1 Dec
Recitation 12
waiting on id recitation12...
Mon 4 Dec
Lab 14
waiting on id lab14...
Tue 5 Dec
Lecture 26
waiting on id lecture26...
Thu 7 Dec
Lecture 27
waiting on id lecture27...
Fri 8 Dec
Recitation 13
waiting on id recitation13...
Fri 15 Dec
(1-4pm)
[null]
final
waiting on id FINAL...

2017 Iliano Cervesato iliano@cmu.edu