CMPSCI 187: Programming With Data
Structures
Lecture 1: Course Overview
What are we doing?
Developing programming maturity in Java
Studying some important data structures
Beginning computer science thinking - analysis of algorithms
Programming Maturity
L&Cs Program for a Key Cipher
L&Cs example program in Section 5.2 encrypts and then decrypts a xed
message (declared as the initial value of a string variable) using such a key
cipher with a key of length 7. Their key letters are small ints, which they
a
Queues to Process Streams
Encrypting and decrypting with a key cipher are examples of stream
processing. The real world offers many situations where a huge amount of
data comes at us, and we must react to each small bit of it as we see it.
This is diffe
L&Cs Simulation of Cinema Cashiers
Their assumptions: A new customer arrives every 15 seconds, a cashier takes
120 seconds to process a customer, customers wait in a real queue for an
available cashier.
With eight or more cashiers, customers never wait
The TicketCounter Class
Single program tests varying numbers of cashiers with the same assumptions
each time. Departure time is arrival + 120 if cashier is free, otherwise time
cashier is done + 120.
public class TicketCounter cfw_
public static void mai
Randomness in Simulation
When we simulate a real world situation, we cant predict the exact behavior
of the actors, but often we have an idea of their range of possible behaviors.
We can use a random number generator to get one of the many possible
scena
Javas Random Number Generators
Java has a class called Math.Random, which provides a variety of
pseudorandom generators. How might we use these in the cinema cashier
simulation?
One method there generates real numbers (doubles) that are uniformly
distri
CMPSCI 187: Programming With Data Structures
Lecture #20: Implementing Linked Lists
25 October 2011
Implementing Linked Lists
L&Cs Single-Link LinkedList Class
The remove Operation for LinkedList
Doubly Linked Lists and the New remove Using find
The L
CMPSCI 187:Programming With Data Structures
Lecture #21: Lists in the Collections Framework
28 October 2011
Lists in the Collections Framework
L&Cs List Classes versus the Real Java Classes
Abstract Classes and Methods
AbstractCollection and AbstractLi
CMPSCI 187: Programming With Data Structures
Lecture #22: Introduction to Recursion
2 November 2011
Introduction to Recursion
What is Recursion, and Why Recursion?
Ungrounded Recursion
The Factorial Function
Tracing Recursive Code: Computing Sums
Ite
CMPSCI 187: Programming With Data Structures
Lecture 23: Examples of Recursion
4 November 2011
Guest Lecturer: Bobby Simidchieva
Examples of Recursion
Recursively Searching a Maze
Depth-First Search Without the seen Field
The Towers of Hanoi Problem
E
CMPSCI 187: Programming With Data Structures
Lecture #24: Introduction to Searching and Sorting
7 November 2011
Introduction to Searching and Sorting
L&Cs SortingAndSearching Class
Static Generic Methods
Linear Search of an Array
Binary Search of a So
CMPSCI 187: Programming With Data Structures
Lecture #25: Sorting: QuickSort and MergeSort
9 November 2011
Sorting: QuickSort and MergeSort
Review of O(n^2) Sorting Algorithms
Divide-And-Conquer Sorting
QuickSort: Thoughtful Divide, Easy Recombine
Mer
CMPSCI 187:Programming With Data Structures
Lecture #26: Trees: Denition and Implementation
16 November 2011
Trees: Denition and Implementation
Tree Vocabulary
Basic Strategies to Implement Trees
Ways to Traverse a Tree
Implementing Trees with Links
CMPSCI 187: Programming With Data Structures
Lecture #27: Expression Trees
18 November 2011
Expression Trees
L&Cs BinaryTreeADT Interface
Some Uses of Binary Trees
Review of LinkedBinaryTree and ArrayBinaryTree Classes
Expression Trees and the Express
CMPSCI 187: Programming With Data Structures
Lecture #28: Binary Search Trees
21 November 2011
Binary Search Trees
The Idea of a Binary Search Tree
The BinarySearchTreeADT Interface
The LinkedBinarySearchTree Class
Adding an Element
Removing An Eleme
CMPSCI 187: Programming With Data Structures
Lecture #29: More on Binary Search Trees
23 November 2011
More on Binary Search Trees
Implementing an Ordered List
Comparing Linked and Tree Implementations
How to Keep a Tree Balanced
Ordinary Right and Le
Key Ciphers
A better method is to use multiple translation systems, and rotate among
them every letter. A convenient way to do this is to adopt a short word as a
key. Lets look at encoding the message ET TU BRUTE with the key
SPQR.
The rst, fth, and nin
Substitution Ciphers
Julius Caesar used a simple cryptosystem to send secret messages to his
generals. Each letter was encoded as the third letter preceding, so D became
A, E became B, and so on, with the last letters wrapping around. (So that in
our alp
CMPSCI 187 Lecture #2
Java Overview
9 September 2011
Java Overview
The Von Neumann Machine Model
Primitive Data in Java
Objects and Pointers
Arrays and Strings
Methods and Scope
The Von Neumann Machine Model
Most computers have a word size, home reg
CMPSCI 187: Programming With Data Structures
Lecture 3: Software Engineering Overview
12 September 2011
Software Engineering Overview
Leftover from Lecture 2: dog example, methods, the call stack, exceptions
Software versus Programs
Software Engineerin
CMPSCI 187: Programming With Data Structures
Lecture 4: Data Structures Overview
14 September 2011
Data Structures Overview
Containers and Collections
Ways to Arrange a Collection
The Stack: Data and Operations
Separating Specication From Implementat
CMPSCI 187: Programming With Data Structures
Lecture 5: Analysis of Algorithms Overview
16 September 2011
Analysis of Algorithms Overview
What is Analysis of Algorithms?
L&Cs Dishwashing Example
Being Usefully Vague About Functions
Important Classes o
CMPSCI 187: Programming With Data Structures
Lecture 6: Collections and Abstract Stacks
19 September 2011
Collections and Abstract Stacks
Catchup: Big-O time for three kinds of searches
The Collections Idea
Terminology: Data Types, Abstract Data Types,
CMPSCI 187: Programming With Data Structures
Lecture 7: Java: Inheritance and Class Hierarchies
21 September 2011
Java: Inheritance and Class Hierarchies
Classes Extending Classes: Subtypes and Supertypes
The Hierarchy of Classes: When is a Reference Le
CMPSCI 187: Programming With Data Structures
Lecture 8: Polymorphism, Generics, and Exceptions
23 September 2011
Polymorphism, Generics, and Exceptions
Object Polymorphism as in the Dog/Terrier Example
Method Polymorphism Through Supertypes
Why Not Alw
CMPSCI 187: Programming With Data Structures
Lecture #9: The Evaluator Program
26 September 2011
The Evaluator Program
The Problem: Postx Evaluation
The Method: Pending Arguments on a Stack
The Structure of L&Cs Solution
The Driver Class Postfix
The
CMPSCI 187: Programming With Data Structures
Lecture 10: The ArrayStack Class
30 September 2011
The ArrayStack Class
Implementing a Stack With an Array
A Generic Stack is an Array of What?
The Fields and the Basic Methods
Stack Overow and Dynamic Resi
CMPSCI 187: Programming With Data Structures
Lecture 11: Linked Data Structures
3 October 2011
Linked Data Structures
The Basic Idea
Advantages and Disadvantages
The Class LinearNode in L&C
Inserting and Deleting in a Linear Linked List
Searching a L
CMPSCI 187: Programming With Data Structures
Lecture 12: Implementing Stacks With Linked Lists
5 October 2011
Implementing Stacks With Linked Lists
Overview: The LinkedStack Class from L&C
The Fields and Constructors
The push Method
The pop Method
Th