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

About this course  [  Description  |  Feedback  |  Readings  |  Software  |  Grading  |  Policies  |  Help  |  Learning Objectives  ]

Description

This course teaches imperative programming and methods for ensuring the correctness of programs. It is intended for students with a basic understanding of programming (variables, expressions, loops, arrays, functions). Students will learn the process and concepts needed to go from high-level descriptions of algorithms to correct imperative implementations, with specific applications to basic data structures and algorithms. Much of the course will be conducted in a subset of C amenable to verification, with a transition to full C near the end. This will be accomplished along three dimensions: After completing 15-122, you will be able to take 15-213 (Introduction to Computer Systems), 15-210 (Parallel and Sequential Data Structures and Algorithms) and 15-214 (Principles of Software System Construction). Other prerequisites or restrictions may apply.

Prerequisites

You must have gotten a 5 on the AP Computer Science A exam or passed 15-112 (Fundamentals of Programming) or equivalent. You may also get permission from an advisor if you performed very high on the CS Assessment on Blackboard.
It is strongly advised that you either have taken or take at the same time either 21-127 (Concepts of Mathematics) or 15-151 (Mathematical Foundations of Computer Science): historically, students who did not ended up with a course grade one letter grade lower than their peers who did, in average.

Past Offerings

F'16 M'16 S'16 F'15 M'15 S'15 F'14 M'14 S'14 F'13 M'13 S'13 F'12 M'12 S'12 F'11 M'11 S'11 F'10

Feedback

It is our goal to make this course successful, stimulating and enjoyable. If at any time you feel that the course is not meeting your expectations or you want to provide feedback on how the course is progressing for you, please contact us. If you would like to provide anonymous comments, please use the feedback form on the course home page or slide a note under our doors. Comments of general interest will be answered on the course discussion board.

Readings

There is no textbook for this course. Lecture notes and other resources are provided through the Schedule tab of this page. We do not require students to read lecture notes before lecture, but those who are interested in reading ahead can certainly do so.

Software

The C0 Language

In the first nine weeks, the course uses C0, a small safe subset of C augmented with a layer to express contracts. This language has been specifically designed to support the student learning objectives in this course. It provides garbage collection (freeing students from dealing with low-level details of explicit memory management), fixed range modular integer arithmetic (avoiding complexities of floating point arithmetic and multiple data sizes), an unambiguous language definition (guarding against relying on undefined behavior), and contracts (making code expectations explicit and localize reasoning).

The C Language

In the last six weeks, the course transitions to C in preparation for subsequent systems courses. Emphasis is on transferring positive habits developed in the use of C0, and on practical advice for avoiding the pitfalls and understanding the idiosyncrasies of C. We use the valgrind tool to test proper memory management.

Programming Environments

You are welcome to use any programming environment that suits you to write your programming assignments. However, all programming homework will be graded by running them on a Unix system using Autolab — you may want to make sure they work on Andrew Unix. Popular environment choices include emacs, vim and sublime, but you should use what works for you: an environment that allows you to write code quickly and efficiently. Here are some useful links:
UnixEmacs

Grading

This is a 10 unit course.

Tasks and Percentages

We are aiming to have homework and exams graded within two days of submission.

Evaluation Criteria

Your assignments and exams are evaluated on the basis of:

Late Policy

Aside from this, there will be no extensions on assignments in general. If you think you really really need an extension on a particular assignment, contact the instructors as soon as possible before the deadline. Please be aware that extensions are entirely discretionary and will be granted only in exceptional circumstances (e.g., due to severe illness or major personal/family emergencies, but not for competitions, club-related events or interviews). The instructors will most likely require confirmation from University Health Services or your academic advisor, as appropriate.

Nearly all situations that lead to asking for an extension to a homework can be avoided with proper planning — often just starting early. Here are some examples:

Grade Appeals

We make mistakes too!
After each exam and homework assignment is graded, you will be able to access your score by clicking on the Grades tab of this page. We will make the utmost effort to be fair and consistent in our grading. Any TA is permitted to fix simple arithmetic errors (and, at their discretion, other blindingly obvious grading errors). For any other grading issues, you must request a regrade as follows:

Final Grades

This class is not curved.

What follows is a rough guide to how course grades will be established, not a precise formula — we will fine-tune cutoffs and other details as we see fit after the end of the course. This is meant to help you set expectations and take action if your trajectory in the class does not take you to the grade you are hoping for (see also the Grades tab on this page). So, here's a rough, very rough heuristics between final grades and total scores: This heuristic assumes that the makeup of a student’s grade is not wildly anomalous: exceptionally low overall scores on exams, programming assignments, or written assignments will be treated on a case-by-case basis. In particular, no student will get an A with an exam average below 80% (no matter how high his/her total score). Furthermore, students who are unable to demonstrate a basic proficiency with the C language in the last few programming assignments will receive a D in the class (this is because 15-122 is a prerequisite to 15-213, a very C-intensive course). For reference, almost a quarter of the students who received a B in Fall 2014 had a 90-100% average on programming assignments, an 80-90% average on written homeworks, and a 70-80% average on exams.
Precise grade cutoffs will not be discussed at any point during or after the semester. For students very close to grade boundaries, instructors may, at their discretion, consider participation in lecture and recitation and exam performance when assigning the final grade.

Academic Integrity

You are expected to comply with the University Policy on Academic Integrity and Plagiarism (see also The Word and Understanding Academic Integrity).

The university policies and procedures on academic integrity will be applied rigorously. All students are required to fill out a form as part of their first assignment indicating that they understand and accept this policy.

The value of your degree depends on the academic integrity of yourself and your peers in each of your classes. It is expected that, unless otherwise instructed, the work you submit as your own is your own work and not someone else’s work or a collaboration between yourself and other(s).

Please read the University Policy on Academic Integrity carefully to understand the penalties associated with academic dishonesty at Carnegie Mellon. In this class, cheating/copying/plagiarism means copying all or part of a program or homework solution from another student or unauthorized source such as the Internet, having someone else do a homework or take an exam for you, knowingly giving such information to another student, reusing answers or solutions from previous editions of the course, or giving or receiving unauthorized information during an examination. In general, each solution you submit (quiz, written assignment, programming assignment, midterm or final exam) must be your own work. In the event that you use information written by another person in your solution, you must cite the source of this information (and receive prior permission if unsure whether this is permitted). It is considered cheating to compare complete or partial answers, discuss details of solutions, or sit near another person who is taking the same course and try to complete the assignment together. It is also considered cheating for a repeating student to reuse one's solutions from a previous semester, or any instructor-provided sample solution. It is a violation of this policy to hand in work for other students.

Your course instructor reserves the right to determine an appropriate penalty based on the violation of academic dishonesty that occurs. Penalties are severe: a typical violation of the university policy results in the student failing this course, but may go all the way to expulsion from Carnegie Mellon University. If you have any questions about this policy and any work you are doing in the course, please feel free to contact the instructors for help.

We will be using the Moss system to detect software plagiarism.

It is not considered cheating to clarify vague points in assignments, lectures, lecture notes, or to give help or receive help in using the computer systems, compilers, debuggers, profilers, or other facilities, but you must refrain from looking at other students' code while you are getting or receiving help for these tools. It is not cheating to review graded assignments or exams with students in the same class as you, but it is considered unauthorized assistance to share these materials between different iterations of the course. Do not post code from this course publicly (e.g., to Bitbucket or GitHub).

Other Policies

Class presence and participation

Active participation by you and other students will ensure that everyone has the best learning experience in this class. We may take participation in lecture and recitation into account when setting final grades. Therefore, please attend the lecture, lab, and recitation you are registered for.

Laptops and mobile devices

As research on learning shows, unexpected noises and movement automatically divert and capture people’s attention, which means you are affecting everyone's learning experience if your cell phone, pager, laptop, etc, makes noise or is visually distracting during class. Therefore, please silence all mobile devices during class. You may use laptops for note-taking only, but please do so from the back of the classroom. Do not work on assignments for this or any other class while attending lecture or recitation.

Students with disabilities

If you wish to request an accommodation due to a documented disability, please inform your instructor and contact Disability Resources as soon as possible (). Special accommodation for exams will be coordinated by the instructors, and must be requested for each exam separately a week in advance.

Getting Help

Personal Health

Take care of yourself.

Do your best to maintain a healthy lifestyle this semester by eating well, exercising, avoiding drugs and alcohol, getting enough sleep and taking some time to relax. This will help you achieve your goals and cope with stress.

All of us benefit from support during times of struggle. You are not alone. There are many helpful resources available on campus and an important part of the college experience is learning how to ask for help. Asking for support sooner rather than later is often helpful.

If you or anyone you know experiences any academic stress, difficult life events, or feelings like anxiety or depression, we strongly encourage you to seek support. Counseling and Psychological Services (CaPS) is here to help: call 412-268-2922 and visit their website. Consider reaching out to a friend, faculty or family member you trust for help getting connected to the support that can help.

If you or someone you know is feeling suicidal or in danger of self-harm, call someone immediately, day or night:
CaPS: 412-268-2922
Re:solve Crisis Network: 888-796-8226
If the situation is life threatening, call the police:
  • On campus (CMU Police): 412-268-2323
  • Off campus: 911
If you have questions about this or your coursework, please let me know.

Communication

For assistance with the written or oral communication assignments in this class, visit the Global Communication Center (GCC). GCC tutors can provide instruction on a range of communication topics and can help you improve your papers and presentations. The GCC is a free service, open to all students, and located in Hunt library. You can make tutoring appointments directly on the GCC website. You may also visit the GCC website to find out about communication workshops offered throughout the academic year.

Learning Objectives

Computational Thinking

Students should leave this course able to explain abstraction and other key computer science concepts, apply these fundamental concepts as problem-solving tools, and wield contracts as a tool for reasoning about the safety and correctness of programs. In particular, we expect students to be able to:
  1. develop contracts (preconditions, postconditions, assertions, and loop invariants) that establish the safety and correctness of imperative programs.
  2. develop and evaluate proofs of the safety and correctness of code with contracts.
  3. develop and evaluate informal termination arguments for programs with loops and recursion.
  4. evaluate claims of both asymptotic complexity and practical efficiency of programs by running tests on different problem sizes.
  5. define the concept of programs as data, and write programs that use the concept.
  6. defend the use of abstractions and interfaces in the presentation of algorithms and data structures.
  7. identify the difference between specification and implementation.
  8. compare different implementations of a given specification and different specifications that can be applied to a single implementation.
  9. explain data structure manipulations using data structure invariants.
  10. identify and evaluate the use of fundamental concepts in computer science as problem-solving tools:
    1. order (sorted or indexed data),
    2. asymptotic worst case, average case, and amortized analysis,
    3. randomness and (pseudo-)random number generation, and
    4. divide-and-conquer strategies.

Programming Skills

Students should leave this course able to read and write code for imperative algorithms and data structures. In particular, we expect students to be able to:
  1. trace the operational behavior of small imperative programs.
  2. identify, describe, and effectively use basic features of C0 and C:
    1. integers as signed modular arithmetic,
    2. integers as fixed-length bit vectors,
    3. characters and strings,
    4. Boolean operations with short-circuiting evaluation,
    5. arrays,
    6. loops (while and for),
    7. pointers,
    8. structs,
    9. recursive and mutually recursive functions,
    10. void pointers and casts between pointer types,
    11. contracts (in C0), and
    12. casts between different numeric types (in C).
  3. translate between high-level algorithms and correct imperative code.
  4. translate between high-level loop invariants and data structure invariants and correct contracts.
  5. write code using external libraries when given a library interface.
  6. develop, test, rewrite, and refine code that meets a given specification or interface.
  7. develop and refine small interfaces.
  8. document code with comments and contracts.
  9. identify undefined and implementation-defined behaviors in C.
  10. write, compile, and test C programs in a Unix-based environment using make, gcc, and valgrind.

Algorithms and Data Structures

Students should leave this course able to describe the implementation of a number of basic algorithms and data structures, effectively employ those algorithms and data structures, and explain and interpret worst-case asymptotic complexity arguments. In particular, we expect students to be able to:
  1. define and describe big-O notation, both formally and informally.
  2. compare common complexity classes like O(1), O(n), O(n log(n)), O(n2), and O(2n).
  3. explain the structure of basic amortized analysis proofs that use potential functions.
  4. apply principles of asymptotic analysis and amortized analysis to new algorithms and data structures.
  5. recognize properties of simple self-adjusting data structures.
  6. recognize algorithms and data structures using divide-and-conquer.
  7. describe and employ a number of basic algorithms and data structures:
    1. integer algorithms,
    2. linear search,
    3. binary search,
    4. sub-quadratic complexity sorting (mergesort and quicksort),
    5. stacks and queues,
    6. pseudo-random number generators,
    7. hash tables,
    8. priority queues,
    9. balanced binary search trees,
    10. disjoint-set data structures (union/find), and
    11. simple graph algorithms.

2017 Iliano Cervesato