CS 241: Data Structures—Spring 2019 Midterm Exam Review Notes
Important note!
click on the triangles to the left to expand or contract sections!
use the text size feature in your browser to make this text larger and more readable!
About the exam
the midterm exam will take place on Friday, March 22nd, at the usual lecture time and place
the exam will be designed so that you should be able to complete it in less than an hour
you will not have access to books, notes, computers, networks or neighbors during the exam
(you may use scratch paper and it will be supplied if needed; you are encouraged to ask your instructor for clarifications during the exam if necessary)
In preparing for the exam, you should consult:
your textbook (see especially chapters and sections mentioned below)
your notes from lecture and lab—these are likely to be especially helpful
the home page for the course and various links, examples, etc., provided there
… and also especially the lab assignments linked from the home page, as well as your programs
Format: the exam will consist of several kinds of questions; typically:
10-12 True-or-False questions at 1-2 points each
8-10 short answer questions at 4-6 points each
1-2 longer answer questions at 8-15 points each
These review notes are not exhaustive, but are meant as a guide to coverage—see other sources for details!
General background to Data Structures and modularity
Chapter 1, section 1.1; also Chapter 3, section 3.1
large software projects are often written and maintained by groups of people
programming language features can allow us to manage complexity by circumscribing various tasks
different classes which implement the same interface can be "plugged" and "unplugged" (replaced) at will
ideally, we unplug a slower implementation and plug in a faster one, each implementing the same interface
a common language of specification, implementation and analysis (O notation) supports communication
the use of standard techniques is valued so that people can understand and modify each other's code
standard solutions to standard problems often involve "tricks" (innovations) that would be hard to come up with on the spot
Math review and recursion
Chapter 1, sections 1.2-1.3
Functions and algorithms
a (mathematical) function is a set of input-output pairs, without regard to how they are computed
the inputs and outputs may be numbers, but also data structures, etc.
an algorithm is a technique for computing a function, step by step method, but still somewhat abstract
a program is a very specific realization of an algorithm in a particular language, with choices of variable names, etc.
these three ideas form a kind of hierarchy, with functions the most abstract and programs the most concrete
the relationships are many-to-one between algorithms and functions, and between programs and algorithms
algorithms have (abstract, O-notation style) running times; functions do not (and programs have real-world running times)
Exponents and logarithms
the logarithm is a very slowly growing function of its argument
technically, the log is the power to which you must bring the base to equal the argument number
roughly, a log in "base b" is the number of digits required to write the argument in base b
so, in base 10, the log of one thousand is 3, and of one million is 6
at the whole power of the base, there is actually one more digit, as the "odometer" turns over
logarithms obey certain mathematical laws similar to those for exponents
example: log (a·b) = log(a) + log(b)
example: log (ak) = k·log(a)
log functions sit below linear functions, and (n log n) sits between linear and squaring in the hierarchy of O-notation (see below)
O notation eliminates the need for specifying the bas of the logarithm, since it ignores constant factors
(but many logs in computing are really base 2)
Basics of recursion
an algorithm is recursive if it refers to itself (calls itself) in its own definition
recursion is often an alternative to iteration (loops)
for non-linear structures (e.g., trees), we may need an auxiliary stack to hold pending nodes while we iterate
recursion is implemented using a stack, one item for each method call
(actually, all method calls are implemented this way, partly out of anticipation of recursion)