CS 3110: Data structures and functional
programming
Final exam
Solutions
1
Problem 1: Expression Evaluation (12 points)
For each of the following OCaml expressions, write the type of the expression and the value
that it evaluates to. If there is no such t
CS 3110: Data structures and functional
programming
Prelim 2
Fall 2013
Thursday, November 21, 7:30 PM
Solutions
do not redistribute.
Instructions
Write your netid on the score page (page 3).
You have 90 minutes to complete this exam. There are six questio
CS 3110: Data structures and functional
programming
Final exam
Solutions
1
Problem 1: Expression Evaluation (12 points)
For each of the following OCaml expressions, write the type of the expression and the value
that it evaluates to. If there is no such t
Lecture 8: Functors Parameterized Modules
For the past few classes we have been considering abstraction and modular design, primarily through the
use of the module mechanism in OCaml. We have seen that good design principles include writing clear
specific
CS 3110: Data structures and functional
programming
Prelim 2
Fall 2013
Thursday, November 21, 7:30 PM
Name:
NetID:
Academic Integrity
I will abide by Cornells policy of academic integrity. I arm that I have not and will not
receive or give help on this ex
CS 3110 Data Structures and Functional Programming
Preliminary Exam #2 Solutions
.
Exercise 1: Warmup
(10 points)
(a) Briey describe the behavior of the following function:
let f : unit -> unit =
let r : (unit -> unit) ref = ref (fun () -> () in
r := (fun
CS 3110: Data structures and functional
programming
Prelim 1
Fall 2013
Thursday, October 10, 7:30 PM
Name:
NetID:
Academic Integrity
I will abide by Cornells policy of academic integrity. I arm that I have not and will not
receive or give help on this exa
Solving recurrences
Note: this page uses the following special characters: Greek capital letter theta: (), Greek capital letter omega (), minus sign
(). If these characters do not appear correctly, your browser is not able to fully handle HTML 4.0, and so
(* - Expression type - *) type bop = Add | Sub | Mul | Div | Pow type uop = Sin | Cos | Ln | Neg type expr = Num of float | Var | BinOp of bop * expr * expr | UnOp of uop * expr
(* - Helper functions - *) let fabs n = if (n < 0.0) then -. n else n let str
exception NotFound t type 'a trie t type 'a cursor (* An empty trie with no bindings *) v val empty: 'a trie (* put m n v inserts value v into m with binding n *) v val put: 'a trie -> char list -> 'a -> 'a trie (* get t k = v if t contains the binding k-
Preliminary Examination I
CS 3110, Cornell University
October 4, 2011
Before starting the exam, write your name and netid on this page (below) and your netid at the
top of each subsequent page. As you go through the exam writing your netid at the top of e
Recitation 1: Introduction to OCaml Syntax
We will use the Objective Caml (OCaml) programming language this semester. OCaml is a functional
language rather than a procedural language; the key difference between these two classes of languages is
the execut
Hash functions
Hash tables are one of the most useful data structures ever invented.
Unfortunately, they are also one of the most misused. Today we will talk
about hash functions. NOTE: you do not need to build your own hash
function for PS5!
Code built u
Recitation 5: Folding and tail recursion
Folding
Suppose we want to write a function to sum a list of integers. By now you should be able to write the
following code:
let rec sum (l : int list) : int =
match l with
[] -> 0
| x : xs -> x + (sum xs)
Now sup
Recitation 18: Recursion Trees and the Master
Method
Recursion Trees
A recursion tree is useful for visualizing what happens when a recurrence is iterated. It diagrams the tree
of recursive calls and the amount of work done at each call.
For instance, con
Lecture 13: The Environment Model
So far, we've used the substitution model to understand how OCaml programs evaluate. The
substitution model is very simple and mechanical. Although there are a zillion cases to deal with in even
a semi-realistic language,
Recitation 2: Tuples, records and datatypes
Tuples
Every function in OCaml takes exactly one value and returns exactly one result. For instance, our
squareRoot function takes one float value and returns one float value. The advantage of always taking
one
Lecture 17: Concurrency
So far in this class we've been talking about sequential programs. Execution of a sequential program
proceeds one step at a time, with no choice about which step to take next. Sequential programs are
somewhat limited, both because
Lecture 19: Asymptotic Complexity and
Recurrences
Asymptotic complexity has limitations, but it is still a useful tool analyzing and improving program
performance. The use of big-O notation simplifies the task of analyzing performance. For OCaml, we
assum
Lecture 21: Amortized Analysis
The claim that hash tables have O(1) expected performance for lookup and insert is based on the
assumption that the number of elements stored in the table is comparable to the number of buckets. If a
hash table has many more
Lecture 21: Graph Representations and
Traversals
A directed graph G is an ordered pair (V, E ) consisting of a set of vertices or nodes V = cfw_v1,.,vn and a
set of edges or arcs E V 2. Generally we denote the number of vertices by |V | or n and the numbe
Lecture 22: Memoization
Even when programming in a functional style, O(1) mutable map abstractions like arrays and hash tables
can be extremely useful. One important use of hash tables is for memoization, in which a previously
computed result is stored in
Memory and Locality
So far we've been talking about performance as though all steps in the evaluation model are equally
expensive. This turns out not to be even approximately true; they can differ by two orders of magnitude or
more. Asymptotically, it doe
More on functors
In last lecture we saw functors and basic examples. Today we will see more examples of those.
Recall that a functor is a module that is parameterized by other modules. Functors allow us to create a
module whose implementation depends on t
Lecture 16: Predicate Logic and Natural
Deduction
Syntax
In propositional logic, the statements we are proving are completely abstract. To be able to prove
programs correct, we need a logic that can talk about the things that programs compute on: integers
Problem Set 1: An Introduction to OCaml
Due Thursday January 31, 23:59
Version: 6
Last modified: Tuesday, January 29, 19:00
Changes:
Version 6: Fixed typos in string_rev "zardoz" and function declaration of
int_of_roman
Version 5: Explicitly banned impe
Problem Set 4: An OCaml Interpreter
Due Thursday, March 14, 23:59
Version: 6
Last Modified: Mon Mar 4 11:55:23 CST 2013
Changes:
Added compare function to the signature for problem 1.4
Specified sort order in problem 1.4 (ascending)
Banned external librar
Problem Set 5: MapReduce
Due Thursday April 11, 2013, 11:59pm
Note: Do not change the .mli files!
Updates/Corrections
Last Updated: Wed Apr 10 09:22 EDT 2013
Fixed the example DNA sequences
Clarified design meeting: discussing MapReduce, not Part 1 (the
Lecture 14: Propositional Logic and Natural
Deduction
Introduction
Propositions
Semantics of Propositions
Tautologies
Introduction
Can we prove that any given program works for all possible inputs? No, that question is undecidable. But
can we develop a pr
Modular Programming
Prof. Clarkson
Fall 2016
Todays music: "Giorgio By Moroder" by Daft Punk
The Moog modular synthesizer
Review
Previously in 3110:
Functions, data
lots of language features
how to build small programs
Today:
language features for bui
Modular Design
Prof. Clarkson
Fall 2016
Todays music: Top Down by Fifth Harmony
Review
Previously in 3110:
language features for modularity: modules, structures,
signatures, abstract types, includes, functors
aspects of modularity: namespaces, abstracti
Functions
Prof. Clarkson
Fall 2016
Todays music: Function by E-40 (Clean remix)
Review
Previously in 3110:
What is a functional language?
Why learn to program in a functional language?
Recitation: intro to OCaml
Today:
Functions: the most important pa
Data Types
Prof. Clarkson
Fall 2016
Todays music: Pokmon Theme by Jason Paige
Review
Previously in 3110:
Functions
Lists
Today:
Let expressions
Ways to define your own data types: variants,
records, tuples
Question
What do you think of A1?
A. It's a m
Introduction to 3110
Prof. Clarkson
Fall 2016
Todays music: Prelude from Final Fantasy VII
by Nobuo Uematsu (remastered by Sean Schafianski)
Welcome!
Programming isnt hard
Programming well is very hard
High variance among professionals productivity:
10