Course Information
• Instructor:Bart Niswonger
226D Sieg Hall
bart@cs.washington.edu
Office hours: M 11:50-12:50, W 1:50-2:50 &
whenever door is open
• TA:
Ashish Sabharwal ashish@cs
Office hours: Tues 10:50-11:50 in 226A/B
• Text: Data Structures & Algorithm Analysis in
C++, 2nd
edition, by Mark Allen Weiss
5.
Tutorials
• Unix I
–Tuesday, June 19th
– 10:50-11:50 + lab time, Sieg 322
• Templates
– Thursday, June 21st
– 10:50-11:50 + lab time, GUG 410
• In place of section
• Unix Development
– Tuesday, June 26th
– 10:50-11:50 + lab time, Sieg 322
REQUIRED
6.
• Roughly weeklywritten homework due at the
start of class on the due date
• Projects (4 total) due by 10PM on the due date
– you have 4 late days for projects
• Grading
– homework: 15%
– projects: 25%
– midterm: 20%
– final: 30%
– best of these:10%
Course Policies
PARTICIPATION!
7.
Course Mechanics
• 326Web page:
www/education/courses/326/01su
• 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++
8.
Goals of theCourse
• 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 and X-windows (you’ll need this in
upcoming courses)
9.
Observation
• All programsmanipulate data
– programs process, store, display, gather
– data can be information, numbers, images, sound
• Each program must decide how to store data
• Choice influences program at every level
– execution speed
– memory requirements
– maintenance (debugging, extending, etc.)
What is anAbstract Data Type?
Abstract Data Type (ADT) -
1) An opportunity for an acronym
2) Mathematical description of an object
and the set of operations on the object
12.
Data Structures :Algorithms
• Algorithm
– A high level, language independent
description of a step-by-step process for
solving a problem
• Data Structure
– A set of algorithms which implement an
ADT
13.
Why so manydata structures?
Ideal data structure:
fast, elegant, memory
efficient
Generates tensions:
– time vs. space
– performance vs.
elegance
– generality vs. simplicity
– one operation’s
performance vs.
another’s
Dictionary ADT
– list
– binary search tree
– AVL tree
– Splay tree
– Red-Black tree
– hash table
14.
Code Implementation
• Theoretically
–abstract base class describes ADT
– inherited implementations implement data structures
– can change data structures transparently (to client
code)
• Practice
– different implementations sometimes suggest different
interfaces (generality vs. simplicity)
– performance of a data structure may influence form of
client code (time vs. space, one operation vs.
another)
15.
ADT Presentation Algorithm
•Present an ADT
• Motivate with some applications
• Repeat until browned entirely through
– develop a data structure for the ADT
– analyze its properties
• efficiency
• correctness
• limitations
• ease of programming
• Contrast data structure’s strengths and weaknesses
– understand when to use each one
16.
Queue ADT
• Queueoperations
– 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
F E D C B
enqueue dequeue
G A
17.
Applications of theQ
• Hold jobs for a printer
• Store packets on network routers
• Hold memory “freelists”
• Make waitlists fair
• Breadth first search
18.
Circular Array QData Structure
void enqueue(Object x) {
Q[back] = x
back = (back + 1) % size
}
Object dequeue() {
x = Q[front]
front = (front + 1) % size
return x
}
b c d e f
Q
0 size - 1
front back
This is pseudocode. Do not correct my semicolons.
When is the Q empty?
Are there error situations this
code will not catch?
What are some limitations of
this structure?
Linked List QData Structure
b c d e f
front back
void enqueue(Object x) {
if (is_empty())
front = back = new Node(x)
else
back->next = new Node(x)
back = back->next
}
Object dequeue() {
assert(!is_empty)
return_data = front->data
temp = front
front = front->next
delete temp
return temp->data
}
LIFO Stack ADT
•Stack operations
– create
– destroy
– push
– pop
– top
– is_empty
• Stack property: if x is on the stack before y is
pushed, then x will be popped after y is popped
LIFO: Last In First Out
A
B
C
D
E
F
E D C B A
F
23.
Stacks in Practice
•Function call stack
• Removing recursion
• Balancing symbols (parentheses)
• Evaluating Reverse Polish Notation
• Depth first search
24.
Array Stack DataStructure
S
0 size - 1
f e d c b
void push(Object x) {
assert(!is_full())
S[back] = x
back++
}
Object top() {
assert(!is_empty())
return S[back - 1]
}
back
Object pop() {
back--
return S[back]
}
bool is_full() {
return back == size
}
25.
Linked List StackData Structure
b c d e f
back
void push(Object x) {
temp = back
back = new Node(x)
back->next = temp
}
Object top() {
assert(!is_empty())
return back->data
}
Object pop() {
assert(!is_empty())
return_data = back->data
temp = back
back = back->next
return return_data
}
26.
Data structures youshould
already know
• Arrays
• Linked lists
• Trees
• Queues
• Stacks
27.
To Do
• Signup on the cse326 mailing list
• Check out the web page
• Log on to a PC in the course labs and
access an instructional UNIX server
• Read Chapters 1 and 3 in the book
28.
Coming Up
• UnixTutorial
– Tuesday (tomorrow) 10:50, Sieg 322
• Multi-Lists
• Priority Queues and Heaps
• Templates Tutorial
• First homework
Editor's Notes
#1 Raise your hand if you can read.
Raise your other hand if you can write.
Stand up if you can think.
WHOOP if you can talk.
Point: this classroom is not sacred ground. I am not a fearsome taskmaster. Please take part in this class, the most horrible thing in the world for an instructor is unresponsive students; don’t be my nightmare!
#3 I’m going to try to tell you at the start of each class what I’ll be covering. Here’s today.
Once we get done with some administrative cruft, we’ll get into the exciting stuff.
#4 Now you swore to me that you could all read, so I’ll just skim over the administrative cruft and hit the high notes.
All this is old news. I’ll also say that I’m going to try to be available after each class for at least a few minutes.
Introduce myself (and Tas introduce themselves if present)
#6 Two things here worth mentioning:
First, late days.
Second, the final category on the grading. Whichever of the first four you do best on gets an extra 10% of weight. That’s good.
#7 GO TO THIS WEB SITE! This and the mailing list will be the primary methods for distributing information.
Note that the programming projects will be graded on UNIX with the g++ compiler. This means: TEST ON UNIX WITH THE G++ COMPILER! Even if you don’t develop with those tools.
#8 This course is designed to familiarize you with the most basic and important data structures in computer science. The ones that will form the foundation of all your future work with computers.
Moreover, you’ll learn how to analyze your programs and data structures so that you know how well they work and what sort of effort in the program is acceptable.
These are the goals of the course as well as my expectations of you.
#9 Given the importance of data, every program uses it, your knowledge of data structures affects what and how well you can program!
Moreover, it helps you understand what is possible to compute.
#10 A method of storage which provides through a set of operations functionality to manipulate the data in some useful way.
#11 Given that this is computer science, I know you’d be disappointed if there were no acronyms in the class. Here’s our first one!
Now, what an ADT really is is the interface of a data structure without any specification of the implementation.
In this class, we’ll study groups of data structures to implement any given abstract data type. In that context…
#12 A data structure will be a set of algorithms for implementing an abstract data type.
One ADT often has many data structures implementing it.
#13 Here’s a simple ADT. The dictionary: like an actual dictionary, it associates some short key piece of information with a longer description of that information. Simple as this interface is, there are at least a dozen data structures, some quite complex, which implement this ADT. Why?
Well, ideally, a data structure is ------------
But not all of these things can necessarily be achieved at once. This creates a set of conflicts which in turn lead us to create many data structures to “solve” any one abstract data type.
#14 The concepts of ADTs and data structures have a nice theoretical translation into C++ code.
Unfortunately, the same tensions which motivate the creation of many data structures for one ADT also affect the way client code might use one data structure over another for the same ADT
We’ll try to not only understand ADTs and data structures, but how to identify and resolve the issues that affect client code in choosing a data structure.
#15 Given those definitions, here’s our first algorithm.
This is how I’m going to try to present each set of data structures to you. You should hold me to this! You’re not getting enough out of the presentation if you don’t see these.
And look, here’s an ADT now…
#16 You’ve probably seen the Queue before. If so, this is a review and a way for us to get comfortable with the format of data structure presentations in this class. If not, this is a simple but very powerful data structure, and you should make sure you understand it thoroughly.
This is an ADT description of the queue. Notice that there are no implementation details. Just a general description of the interface and important properties of those interface methods.
#17 Qs are used widely in computer science. This is just a handful of the high profile uses, but _many_ programs use queues.
#18 Here is a data structure implementation of the Q.
The queue is stored as an array, and, to avoid shifting all the elements each time an element is dequeued, we imagine that the array wraps around on itself.
This is an excellent example of how implementation can affect interface: notice the “is_full” function.
There’s also another problem here. What’s wrong with the Enqueue and Dequeue functions?
Your data structures should be robust! Make them robust before you even consider thinking about making them efficient! That is an order!