Transcript lecture01b

Come on down!
• Take and fill out a survey
• Get a copy of lecture slides
• Please sit in the first 5 rows!
CSE 326: Data Structures
Lecture #1
Introduction
Dan Suciu
Winter Quarter 2003
Today’s Outline
•
•
•
•
Administrative Stuff
Overview of 326
Survey
Introduction to Complexity
Course Information
• Instructor: Dan Suciu <suciu@cs>
Office hours: Mon. 2:30-3:30, 318 Sieg Hall
• TA: Nilesh Dalvi <nilesh@cs>
Office hours: TBA.
• TA (1/2): Adam Fuchs (afuchs@cs)
• Sections are held in: BLD 392, MEB 243.
• Text: Data Structures & Algorithm Analysis in
Java 2nd edition, by Mark Allen Weiss
Course Policies
• Written homeworks
– Due at the start of class on due date
• Programming projects
– Turned in electronically before 11pm on due date to
Nilesh Dalvi
• No late homeworks accepted
• Work in teams only on explicit team projects
– See website
• Grading
– Weekly assignments:
– Midterm:
– Final:
50%
20%
30%
Course Mechanics
• 326 Web page: www/education/courses/326/03wi
• 326 course directory: /cse/courses/cse326
• 326 mailing list: [email protected]
– subscribe using instructions on the 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 in java
(preferred) or gcc
– OK to develop using other tools (e.g. under Windows)
but make sure you test under UNIX
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?
Clever? Efficient?
Lists, Stacks, Queues
Heaps
Binary Search Trees
AVL Trees
Hash Tables
Graphs
Disjoint Sets
Data Structures
Insert
Delete
Find
Merge
Shortest Paths
Union
Algorithms
Graphics
Theory
AI
Applications
Systems
Used Everywhere!
Mastery of this
material separates
you from:
• Perhaps the most important course in your CS curriculum!
• Guaranteed non-obsolescence!
Example 1
• Towers of Hanoi:
http://www.cut-the-knot.com/recurrence/hanoi.shtml or
http://www.mazeworks.com/hanoi/
• Question to class: how long will it run for
n = 10
n = 20
n = 50
n = 100
Example 1
• How many moves do we need to solve it for some n ?
T(1) = 1
T(n) = T(n-1) + 1 + T(n-1)
= 2 T(n-1) + 1
It follows that T(n) = (2n – 1)T, where T=T(1) (why ?)
• We know T(6) = 1 second
• Running times are (approximate):
n = 10
 T(10)  24 seconds = 16 seconds
n = 20
 T(20)  214 seconds = over one hour
n = 50
 T(50)  244 seconds  1014seconds  3 million years
n = 100
 T(100)  294 seconds  1030 seconds
(only 3 1017 seconds since Big Bang !)
Example 2
• 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…
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
Asymptotic Complexity
• This course is about asymptotic complexity
– Deals with algorithms, and their analysis
• It is not about better coding
– Does not deal with coding details
I don’t need to
take 326 because:
• I can buy a faster laptop
• I can write very good code
The Apocalyptic Laptop
Seth Lloyd, SCIENCE, 31 Aug 2000
5.4 x 10 50 operations per second
What a Better Laptop Buys You
1E+60
1 year
1 second
1E+55
1E+50
2^N
1E+45
1E+40
1.2^N
1E+35
N^5
1E+30
1E+25
N^3
5N
Ultimate
Laptop,
Since
Big Bang Today’s
laptop
1 day
(1000MIPS)
1E+20
1E+15
1E+10
100000
1
1
10
100
1000
Not much...
What Better Coding Buys You
1E+59
1 year
1 second
1E+54
1E+49
Ultimate
Laptop,
1E+44
1E+39
2^N
2^N/10
1E+34
Since
Big Bang Today’s
laptop
1 day
(1000MIPS)
1E+29
1E+24
1E+19
1E+14
1E+09
10000
0.1
1
10
100
1000
Ten times faster buys you…
…nothing
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)
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!
A Second Hurdle
2. Unix
Experience 1975 all over again!
– Try to login, edit, create a Makefile, and
compile your favorite “hello world” program
right away
– Programming Assignment 0 due next Monday
– Bring your questions and frustrations to
Section on Thursday!
A Third Hurdle: Java
Public class Set_of_ints {
Public void insert( int x );
Public void remove( int x ); …
}
Review the syntax
Run your first program (assignment 0)
Handy Library
• From Weiss:
http://www.cs.fiu.edu/~weiss/dsaajava/code/
• most of CSE 326 in a box
– don’t use (unless told); we’ll be rolling our own
Java  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 Java in class.
Abstract Data Types
Abstract Data Type (ADT)
Mathematical description of an
object and the set of operations
on the object
tradeoffs!
Data Types
integer, array,
pointers, …
Algorithms
binary search,
quicksort, …
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
First Example: Queue ADT
• Queue operations
–
–
–
–
–
create
destroy
enqueue G enqueue
dequeue
is_empty
FEDCB
dequeue
A
• Queue property: if x is enQed before y is enQed,
then x will be deQed before y is deQed
FIFO: First In First Out
Applications of the Q
•
•
•
•
Hold jobs for a printer
Store packets on network routers
Make waitlists fair
Breadth first search
Circular Array Q Data Structure
Q
0
size - 1
b c d e f
front
back
enqueue(Object x) {
Q[back] = x ;
back = (back + 1) % size
}
How test for empty list?
dequeue() {
x = Q[front] ;
front = (front + 1) % size;
return x ; }
What is complexity of
these operations?
How to find K-th
element in the queue?
Limitations of this
structure?
Linked List Q Data Structure
b
c
d
front
enqueue(Object x) {
back.next = new Node(x);
back = back.next; }
dequeue() {
saved = front.data;
temp = front;
front = front.next;
return saved;}
e
f
back
What are tradeoffs?
• simplicity
• speed
• robustness
• memory usage
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