You’re in the right place if you want to *improve* your Java programming
skills and learn lots about the various ways to *organize data efficiently*
for your applications.
You’ll also learn about analysis of algorithms, formal specifications,
automated unit testing, performance analysis, and a few more things.

**Catalog Description:**
This course covers the analysis, design, and implementation of data
structures including arrays, stacks, queues, linked lists, binary trees,
heaps, balanced trees, and graphs.
Other topics include sorting, hashing, Java generics, unit testing, and
benchmarking.
Course work involves both written homework and Java programming assignments.

**Prerequisite(s):** 601.107: Introductory Programming in Java
or 601.220: Intermediate Programming.

**Policies:**
Please read the
general course policies
and take them to heart.
Additional policies specific to this course may be posted at a later date.

**Instructor:**Peter H. Fröhlich**Piazza:**http://piazza.com/jhu/spring2018/601226 (public discussion / questions)**Staff:**cs226-staff@bloat.org (private / grading questions)**Lecture:**Monday, Wednesday, Friday, noon – 1:15 pm**Location:***Maryland 110*(effective 2018/02/09, was Mergenthaler 111)**Midterm:**Wednesday, March 14, in lecture**Final:**Monday, May 14, 2:00 pm – 5:00 pm

There is *no required text book* for this course, but it’s *highly
recommended* that you obtain reference material to supplement lecture.
Here are some suggestions.

- Shaffer, Cliff: OpenDSA. Interactive online text. (An older version is available in print if you prefer that.)
- Sedgewick, Wayne: Algorithms. Fourth Edition, Pearson, 2011. Also available online at JHU.
- Cormen, Leiserson, Rivest, Stein: Introduction to Algorithms. Third Edition, MIT Press, 2009. Also available online at JHU. (This text is often required for 600.363 / 463: Introduction to Algorithms.)
- Weiss: Data Structures and Algorithm Analysis in Java Third Edition, Pearson, 2012.

- Dean, Dean: Introduction to Programming with Java: A Problem Solving Approach. Second Edition, McGraw-Hill, 2013. (This text has recently served as the required text for 600.107: Introductory Programming in Java.)
- Sestoft: Java Precisely. Third Edition, MIT Press, 2016.
- Deitel, Deitel: Java How to Program. Ninth Edition, Pearson, 2012. Also available online at JHU.
- Flanagan: Java in a Nutshell. Fifth Edition, O’Reilly, 2005.

- algoviz.org collection of visualizations for various data structures and algorithms

- Java API description of Java classes and methods
- Code Examples from Intro Programming in Java (600.107); look in the sub-directories for examples of each topic.
- Checkstyle Overview
briefly discusses several issues around
`checkstyle`

that you may run into

- Joanne’s CS@JH Account Basics
- Joanne’s Unix Overview describes key commands
- An excellent Unix Tutorial
- A printable Unix Reference Card
- Learning emacs: Reference Card, Beginner’s Tutorial, GNU Emacs Tutorial, GNU Emacs Reference Card
- Learning nano: Nano Tutorial, GNU Nano Website
- Learning vi: Reference Card, Beginner’s Guide, Cheat Sheet Tutorial, Interactive Tutorial

- Assignments (about 10): 50%
- Midterm: 20%
- Final: 30%

Please check the individual assignments for due dates and the structure your solutions should have. See the course policies for detailed submission instructions.

- Assignment 0
- Assignment 1
- Assignment 2
- Assignment 3
- Assignment 4
- Assignment 5
- Assignment 6
- Assignment 7
- Assignment 8
- Assignment 9

If you have an opinion on these assignments, be it good or bad, please let us know about it. We’re always trying to make these things more enjoyable (if that’s an applicable term? :-).

This is *not* a schedule.
It’s a “log” of what we did, roughly, in each lecture.
Don’t expect it to turn into a schedule, it won’t.
Also there *will* eventually be gaps, sorry.

- January 29: Welcome; course overview; course policies; bookstore examples, linear vs binary search.
- January 31: Bookstores continued, binary search trees, tries;
operations on data restrict possible data structures (e.g. equality,
total order, decomposition);
demo of VirtualBox and Lubuntu;
review of compiling/running Java code;
difference between standard output and standard error;
the
`-Xlint:all`

compiler option; using`checkstyle`

to enforce consistent programming style; putting together (and double-checking!)`.tar.gz`

archives for submissions. - February 2: Interface versus implementation;
the “conceptual” counter box and possible implementations
(mechanical, electronic, hamster contraption, etc.);
introduction to interfaces in Java;
the
`Counter`

interface; Java classes as implementations; the`SimpleCounter`

implementation; testing the`SimpleCounter`

implementation; using`assert`

for automated, self-contained testing; a second`WeirdCounter`

implementation plus test cases. - February 5: Interface versus specification versus implementation;
specifications attach meaning (semantics) to interfaces (syntax);
informal versus formal specifications;
algebraic specifications of abstract data types;
notation for specifications;
about the presumed
`Integer`

specification; developing three variants of the`Counter`

specification; design tradeoff: how*specific*should a specification be? - February 7: Developing a specification for
`Variable`

; ADT notation for type parameters and constraints; the`Any`

specification, equals operation; ADT notation for functions with multiple parameters; see Piazza for writeups of all the specifications; introduction to generics in Java; hacking a`Variable`

interface and a`SimpleVariable`

implementation plus test cases. - February 9: Developing a specification for the
`Array`

ADT; partial functions and preconditions in specifications. - February 12: Hacking an
`Array`

interface and a`SimpleArray`

implementation; exceptions in Java to enforce precondition (for partial functions in the specification); the difference between`Exception`

and`RuntimeException`

in Java; testing`SimpleArray`

; deriving test cases from the specification; testing exceptions. - February 14: Additional test cases for Java-only methods such as
`toString`

; review of Java’s for-each loop; the`Iterable`

and`Iterator`

interfaces in Java; adjusting the`Array`

interface to be iterable; implementing the iterator as a nested class in Java. - February 16: Hacking a second implementation of
`Array`

based on singly-linked lists; nested class for`Node`

objects; inner class for`Iterator`

implementation; adapting the`SimpleArray`

test cases. - February 19: The
`Stack`

ADT; developing a specification for`Stack`

; the problem with`equals`

for stacks, why we don’t want to be “programming” in specifications; the`Stack`

interface; implementation with a singly-linked list; appending vs. prepending nodes on`push`

, implications for`pop`

; implementation with a Java array; tracking the “used” portion of the array; the trouble with`push`

: whatever the size of the array, it’s wrong, we need to “resize” the array when necessary. - February 21: How to “resize” an array for the
`ArrayStack`

implementation: make a bigger one (twice as big is good), copy existing data, then “switch” the arrays; introduction to sorting; specifying what “sorted” means; in place / in situ sorting algorithms; stable sorting algorithms; a “silly” sorting algorithm that takes up to n! steps; “better” sorting algorithms that take roughly n^2 steps: bubble sort, selection sort, insertion sort. - February 23:
**(Hamima Nasrin)**Analysis of algorithms; experimental versus formal (asymptotic) analysis; analysis of linear search; O-notation; analysis of basic insertion sort. - February 26:
**(Tony Dear)**Stack review; queue interface; queue implementation using lists; performance tradeoffs between representations; queue implementation using arrays; performance tradeoffs, using modulus to “fake” cyclic arrays; intro to deques (double-ended queues). - February 28:
*Analysis of algorithms redux:*focus on time (and space), other dimensions possible; almost always worst case, sometimes average case is more informative, best case is usually just a curiosity; remember that we look at “large n” in the big picture; typical complexity classes (constant, linear, quadratic); think of O(…) as a set of functions;*Stack redux:*infix, prefix, and postfix notation for expressions; using stacks to evaluate postfix expressions;*Queues redux:*visualizing stack, queue, and deque as abstractions with 1, 1.5, or 2 “ends” where “stuff happens”; LIFO versus FIFO behavior; why front and back are where they are for the array implementation; modulus reconsidered (varying definitions for negative integers across languages, try to keep everything positive to be safe, the “+n” trick); resizing the array representation of queues (and deques); picking representations to allow for simple, concise, and fast code. - March 2: The JUnit 4 testing framework;
the
`@Test`

and`@Before`

annotations; the`assertEquals`

,`assertTrue`

,`assertFalse`

methods; using`static`

imports to avoid`Assert.assertEquals`

and so on; some background on`jar`

files; using`-classpath`

to compile and run JUnit 4 test cases; extended example of writing the`Counter`

tests; testing against interfaces by splitting tests into base class (which has the general interface test cases) and derived classes (which instantiate the unit under test and have implementation-specific tests). - March 5: Amortized analysis over a sequence of data-structure operations;
normal worst-case analysis says
`push`

is O(n) in`ArrayStack`

; more detailed analysis shows that`push`

is**amortized**O(1) instead; long discussion of the list abstraction, especially the need for abstract positions; contrast to array and deque abstractions; starting on the interface for`List`

. - March 7: The “standard”
`List`

implementation as a doubly-linked list of node objects; how to think about / visualize the implementation over time; figuring out`insertFront`

in some detail, focus on getting “pointers” or “references” between nodes (and the list object itself) right; “disguising”`Node`

as`Position`

; validating positions. - March 9: Using sentinel nodes instead of
`null`

pointers; simplifying the implementation; introduction to experimental analysis (think “physics lab”); contrasting asymptotic and experimental analysis; the`jaybee`

framework for benchmarking; examples (building up long strings, comparing the cost of basic integer operations). - March 12: More examples of experimental analysis using
`jaybee`

(copying and initializing arrays, comparing Java’s`LinkedList`

and`ArrayList`

); a bit of midterm Q&A. - March 14: Midterm Exam.
- March 16: Introduction to trees as a position-oriented ADT;
applications for trees (user interfaces, page layout, text book structure,
management hierarchy, JSON/XML/HTML, etc.);
developing the
`Tree`

interface for generic, n-ary trees; implementation options for the`Tree`

interface (using lists, arrays, or parent-sibling representation, various tradeoffs). - March 26: Tree traversals (breadth-first or level-ordered using a queue,
depth-first using recursion, difference between pre, in, and post-order
traversals);
introduction to graphs as a position-oriented ADT;
graph terminology, specifically paths and cycles;
self-loops restriction, duplicate edges restriction;
applications of graphs;
developing the
`Graph`

interface, our first with*two*generic type parameters. - March 28: Splitting
`Position`

into`Vertex`

and`Edge`

to allow better type-checking and enable overloading; returning`Iterable<Vertex<V>>`

and`Iterable<Edge<E>>`

from methods that have many results; sparse versus dense graphs; implementation options for graphs (adjacency matrix for dense graphs, incidence lists for sparse graphs, detailed sketch of incidence list representation). - lost a bunch, sorry (March 30, April 2, April 4); we did sets mostly, including adaptive and ordered sets
- April 6: Introduction to Priority Queues; Southwest Airlines example;
minimum vs. maximum priority queues; interface design with more neutral
names; why
`Comparator`

; simple priority queue implementation based on arrays; introduction to binary heaps; shape property; ordering property; implications for min/max depending on ordering relationship; inserting into binary heaps; removing from binary heaps; outline of O(log n) for both; how to map heaps into arrays. - April 9: More about mapping heaps into arrays; adjusting parent/left/right computations if slot 0 is to be used; brief excursion to C land; introduction to heapsort, our first O(n log n) sorting algorithm; demo of heapsort vs. all the other sorting algorithms; how to derive an in-situ (in-place) heapsort.