15-122 Assignment 6
Page 1 of 5
15-122 : Principles of Imperative Computation
Fall 2012
Assignment 6 Selected Solutions
(Theory Part)
The following solutions are provided to you to help you study this semester. They are not
to be distributed to others out
15-122 : Principles of Imperative Computation, Fall 2014
Written Homework 4
Due: Monday, September 22, 2014
Name:
Andrew ID:
Section:
This written homework covers big O notation and some reasoning about searching and
sorting algorithms. You will use some
15-122 Assignment 4
Page 1 of 8
15-122 : Principles of Imperative Computation
Summer 1 2012
Assignment 4
(Theory Part)
Due: Monday, June 11, 2012 in class
Name:
Andrew ID:
Recitation:
The written portion of this weeks homework will give you some practice
15-122 Homework 4
Page 1 of 10
15-122 : Principles of Imperative Computation, Spring 2013
Homework 4 Theory
Due: Thursday, March 7, 2013, at the beginning of lecture
Name:
Andrew ID:
Recitation:
The written portion of this weeks homework will give you som
15-122 : Principles of Imperative Computation, Fall 2014
Written Homework 3
Due: Monday, September 15, 2014
Name:
Andrew ID:
Section:
This written homework covers specifying and implementing search in an array and how to
reason with contracts. You will us
15122: Principles of Imperative Computation
M IDTERM E XAM 1
S AMPLE S OLUTIONS
October 2, 2014
This exam is closed book with one sheet of notes permitted.
You have 80 minutes to complete the exam.
There are 12 pages in this examination, comprising 4 q
15-122 Homework 1
Page 1 of 12
15-122: Principles of Imperative Computation, Spring 2013
Homework 1 Programming: Imagelab
Due: Monday, February 4, 2013 by 23:59
For the programming portion of this weeks homework, youll review how images are stored
in the
15-122 : Principles of Imperative Computation, Fall 2014
Written Homework 5
Due: Monday, September 29, 2014
Name:
Andrew ID:
Section:
This written homework covers asymptotic complexity for a new algorithm, the visualization
of pointers in C0, and the use
Lecture Notes on
Types in C
15-122: Principles of Imperative Computation
Frank Pfenning, Rob Simmons
Lecture 20
April 2, 2013
1
Introduction
In lecture 18, we emphasized the things we lost by going to C:
Many operations that would safely cause an error i
Lecture Notes on
Sorting
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 7
February 5, 2013
1
Introduction
We begin this lecture by discussing how to compare running times of functions in an abstract, mathematical way. The same underly
Lecture Notes on
Hash Tables
15-122: Principles of Imperative Computation
Frank Pfenning, Rob Simmons
Lecture 13
February 28, 2013
1
Introduction
In this lecture we re-introduce the dictionaries that were implemented as a
part of Clac and generalize them
15-122: Principles of Imperative Computation
Recitation 18
Josh Zimmerman
Macros
C has a concept of macros. Macros are simple find and replace expressions that get run at compile time. These can
be useful for constants, things that edit the syntax of your
Lecture Notes on
Interfaces
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 14
October 16, 2012
1
Introduction
The notion of an interface to an implementation of an abstract data type or library is an extremely important concept in com
Lecture Notes on
Generic Data Structures
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 22
November 15, 2012
1
Introduction
Using void* to represent pointers to values of arbitrary type, we were able
to implement generic stacks in tha
Lecture Notes on
Memory Management
15-122: Principles of Imperative Computation
Frank Pfenning, Rob Simmons
Lecture 18b
March 26, 2013
1
Introduction
In this lecture we will start the transition from C0 to C. In some ways, the
lecture is therefore about k
Lecture Notes on
Stacks & Queues
15-122: Principles of Imperative Computation
Frank Pfenning, Andre Platzer, Rob Simmons
Lecture 9
February 12, 2013
1
Introduction
In this lecture we introduce queues and stacks as data structures, e.g., for
managing tasks
Lecture Notes on
Hash Tables
15-122: Principles of Imperative Computation
Frank Pfenning, Rob Simmons
Lecture 13
February 28, 2013
1
Introduction
In this lecture we re-introduce the dictionaries that were implemented as a
part of Clac and generalize them
Lecture Notes on
Unbounded Arrays
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 12
February 21, 2012
1
Introduction
Most lectures so far had topics related to all three major categories of learning goals for the course: computational
Lecture Notes on
AVL Trees
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 19
March 28, 2013
1
Introduction
Binary search trees are an excellent data structure to implement associative arrays, maps, sets, and similar interfaces. The ma
Lecture Notes on
Search in Graphs
(Partial Draft)
15-122: Principles of Imperative Computation
Frank Pfenning, Andre Platzer, Rob Simmons
Lecture 24
April 23, 2013
1
Introduction
In this lecture we introduce graphs. Graphs provide a uniform model for
many
15-122: Principles of Imperative Computation
Recitation Week 3
Rob Simmons
In class, we covered one quadratic sort, selection sort, and two O(n log n) sorts, quicksort and mergesort.
To practice with thinking about sorts in terms of loop invariants, today
Midterm II Exam
15-122 Principles of Imperative Computation
Tom Cortina and Rob Simmons
November 6, 2014
Name:
Andrew ID:
Recitation Section (specify letter):
Instructions
This exam is closed-book with one sheet of notes permitted.
You have 80 minutes t
15-122: Principles of Imperative Computation
Recitation Week 4
Nivedita Chopra, Rob Simmons
Checkpoint 0
Write a function to reverse a queue, using only the functions from the stack and queue interfaces.
1 void reverse(queue Q) cfw_
2
/ Hint : Allocate a
15-122: Principles of Imperative Computation
Recitation Week 2
Josh Zimmerman, Nivedita Chopra
Checkpoint 0
A water main break in GHC has, confusingly, broken the C0 compilers -d option! C0 contracts are
now being treated as comments, and the only way to
Lecture Notes on
Binary Search
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 6
January 31, 2013
1
Introduction
One of the fundamental and recurring problems in computer science is to
find elements in collections, such as elements in
Lecture Notes on
Tries
15-122: Principles of Imperative Computation
Thomas Cortina, Frank Pfenning, Rob Simmons
Lecture 21
April 4, 2012
1
Introduction
In the data structures implementing associative arrays so far, we have needed
either an equality operat
Lecture Notes on
Restoring Invariants
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 17
October 23, 2012
1
Introduction
In this lecture we will implement operations on heaps. The theme of this
lecture is reasoning with invariants that
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 and discuss several possible implementations. We th
Lecture Notes on
Ints
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 3
January 22, 2013
1
Introduction
Two fundamental types in almost any programming language are booleans
and integers. Booleans are comparatively straightforward: the
Lecture Notes on
Arrays
15-122: Principles of Imperative Computation
Frank Pfenning, Andre Platzer
Lecture 4
January 24, 2012
1
Introduction
So far we have seen how to process primitive data like integers in imperative programs. That is useful, but certai
15-122: Principles of Imperative Computation
Recitation 16
Josh Zimmerman
Binary search treesa quick recap
Binary search trees are an implementation of associative arrays in a tree structure. We maintain the
invariant (an ordering invariant) that everythi
Lecture Notes on
Pointers
15-122: Principles of Imperative Computation
Frank Pfenning, Rob Simmons
Lecture 9
February 14, 2013
1
Introduction
In this lecture we complete our discussion of types in C0 by discussing
pointers and structs, two great tastes th
15-122: Principles of Imperative Computation
Recitation 21a
Nivedita Chopra, Josh Zimmerman
Exam!
The exam is on Tuesday and theres a review session on Sunday (April 7) from 3:00-5:00PM in GHC 4401 (Rashid,
where lecture meets). Make sure to bring your st
Lecture Notes on
Quicksort
15-122: Principles of Imperative Computation
Frank Pfenning
Lecture 8
February 7, 2013
1
Introduction
In this lecture we first sketch two related algorithms for sorting that achieve
a much better running time than the selection