4. Course Information
• Instructor: Alon Halevy <alon@cs>
Office hours: Wed. 4:30-5:30, 310 Sieg Hall
• TA: Maya Rodrig <rodrig@cs>
Office hours: Monday 1:30-2:30.
Meet in Sieg 226B
• TA (1/2) (and C++ expert): Nicholas Bone (bone@cs)
• Sections are held in: BLD 392, EE1 031.
• Text: Data Structures & Algorithm Analysis in C++,
2nd edition, by Mark Allen Weiss
5. Course Policies
• Several written homeworks
– Due at the start of class on due date
• Several programming projects
– Projects turned in electronically before 11pm on due date
• 10% penalty for 1 weekday late; afterward, NOT accepted
• Work in teams only on explicit team projects
• Grading
– homework: 25%
– projects: 25%
– midterm: 20%
– final: 30%
6. Course Mechanics
• 326 Web page: www/education/courses/326/01sp
• 326 course directory: /cse/courses/cse326
• 326 mailing list: cse326@cs.washington.edu
– subscribe to the mailing list using majordomo, see
homepage
• Course labs are 232 and 329 Sieg Hall
– lab has NT machines w/X servers to access UNIX
• All programming projects graded on UNIX/g++
7. What is this Course About?
Clever ways to organize information in order to
enable efficient computation
– What do we mean by clever?
– What do we mean by efficient?
8. Clever? Efficient?
Lists, Stacks, Queues
Heaps
Binary Search Trees
AVL Trees
Hash Tables
Graphs
Disjoint Sets
Insert
Delete
Find
Merge
Shortest Paths
Union
Data Structures Algorithms
9. Used Everywhere!
Mastery of this
material separates
you from:
Systems
Theory
Graphics
AI
Applications
• Perhaps the most important course in your CS curriculum!
• Guaranteed non-obsolescence!
10. Anecdote #1
• N2 “pretty print” routine nearly dooms major
expert system project at AT&T
– 10 MB data = 10 days (100 MIPS)
– programmer was brilliant, but he skipped 326…
11. Asymptotic Complexity
Our notion of efficiency:
How the running time of an algorithm scales with the
size of its input
– several ways to further refine:
• worst case
• average case
• amortized over a series of runs
14. Specific Goals of the Course
• Become familiar with some of the fundamental data
structures in computer science
• Improve ability to solve problems abstractly
– data structures are the building blocks
• Improve ability to analyze your algorithms
– prove correctness
– gauge (and improve) time complexity
• Become modestly skilled with the UNIX operating
system (you’ll need this in upcoming courses)
15. One Preliminary Hurdle
1. Recall what you learned in CSE 321 …
– proofs by mathematical induction
– proofs by contradiction
– formulas for calculating sums and products of series
– recursion
Know Sec 1.1 – 1.4 of text by heart!
16. A Second Hurdle
• Unix
Experience 1975 all over again!
– Try to login, edit, create a Makefile, and compile your
favorite “hello world” program right away
– Programming Project #1 distributed Wednesday
– Bring your questions and frustrations to Section on
Thursday!
17. A Third Hurdle: Templates
class Set_of_ints {
public:
insert( int x );
boolean is_member( int x ); … }
template <class Obj> class Set {
public:
insert( Obj x );
boolean is_member( Obj x ); … }
Set <int> SomeNumbers;
Set <char *> SomeWords;
18. In Every Silver Lining, There’s a Big
Dark Cloud – George Carlin
• Templates were invented 12 years ago, and still no
compiler correctly implements them!
• Using templates with multiple source files tricky
– See Course Web pages and TAs for best way
• MAINTAINING SANITY RULE
– Write/debug first without templates
– Templatize as need
– Keep it simple!
19. Handy Libraries
• From Weiss:
vector < int > MySafeIntArray;
vector < double > MySafeFloatArray;
string MySafeString;
• Like arrays and char*, but provide
– bounds checking
– memory management
• STL (Standard Template Library)
– most of CSE 326 in a box
– don’t use (unless told); we’ll be rolling our own
20. C++ Data Structures
One of the all time great books in computer science:
The Art of Computer Programming (1968-1973)
by Donald Knuth
Examples in assembly language (and English)!
American Scientist
says: in top 12 books
of the CENTURY!
Very little about C++ in class.
21. Abstract Data Types
Data Types
integer, array,
pointers, …
Abstract Data Type (ADT)
Mathematical description of an
object and the set of operations
on the object
Algorithms
binary search,
quicksort, …
tradeoffs!
22. ADT Presentation Algorithm
• Present an ADT
• Motivate with some applications
• Repeat until it’s time to move on:
– develop a data structure and algorithms for the ADT
– analyze its properties
• efficiency
• correctness
• limitations
• ease of programming
• Contrast strengths and weaknesses
23. • Queue operations
– create
– destroy
– enqueue
– dequeue
– is_empty
• Queue property: if x is enQed before y is enQed,
then x will be deQed before y is deQed
FIFO: First In First Out
First Example: Queue ADT
F E D C B
enqueue dequeue
G A
24. Applications of the Q
• Hold jobs for a printer
• Store packets on network routers
• Make waitlists fair
• Breadth first search
25. Circular Array Q Data Structure
enqueue(Object x) {
Q[back] = x ;
back = (back + 1) % size }
b c d e f
Q
0 size - 1
front back
dequeue() {
x = Q[front] ;
front = (front + 1) % size;
return x ; }
How test for empty list?
How to find K-th
element in the queue?
What is complexity of
these operations?
Limitations of this
structure?
26. Linked List Q Data Structure
b c d e f
front back
enqueue(Object x) {
back->next = new Node(x);
back = back->next; }
dequeue() {
saved = front->data;
temp = front;
front = front->next;
delete temp ;
return saved;}
What are tradeoffs?
• simplicity
• speed
• robustness
• memory usage
27. To Do
• Return your survey before leaving!
• Sign up on the cse326 mailing list
• Check out the web page
• Log on to the PCs in course labs and access an
instructional UNIX server
• Read Chapters 1 and 2 in the book