260 likes | 288 Views
CSE 326 Introduction. David Kaplan Dept of Computer Science & Engineering Autumn 2001. People. Instructor David Kaplan ( davek@cs ) Teaching Assistants Adrien Treuille ( treuille@cs ) Hannah Tang ( hctang@cs ) Coach, Guest Lecturer Donald Chinn ( dci@cs ). Filling the Void.
E N D
CSE 326Introduction David Kaplan Dept of Computer Science & Engineering Autumn 2001
People Instructor David Kaplan (davek@cs) Teaching Assistants Adrien Treuille (treuille@cs) Hannah Tang (hctang@cs) Coach, Guest Lecturer Donald Chinn (dci@cs) CSE 326 Autumn 2001 2
Filling the Void Source: New York Times, September 23, 2001 http://www.nytimes.com/2001/09/23/magazine/23MYODA.html Artists: Paul Myoda and Julian LaVerdiere
Course Organization Course Web • http://www.cs.washington.edu/education/courses/326/01au/ Schedule Requirements and Grading • 4 Homeworks (20%) • 4 Quizzes (20%) • 4 Programming Projects (25%), graded on UNIX/g++ • Final (30%) • Instructor discretion (5%) • No Midterm Policies CSE 326 Autumn 2001 4
Resources Text • M. A. Weiss, Data Structures & Algorithms in C++, 2nd ed. Computing Lab • 232 and 329 Sieg • NT machines with X servers to access UNIX Course email • cse326@cs.washington.edu • Subscribe via majordomo Lecture Slides • PYO (print your own) • Posted by 12:00am, night before lecture • Formats: lecture web, .ppt CSE 326 Autumn 2001 5
Why study data structures? Clever ways to organize information in order to enable efficient computation Databases AI Theory Graphics Networking Games Systems Applications Data Structures CSE 326 Autumn 2001 6
Why take CSE 326? • Guaranteed non-obsolescence • May be most important CS course you ever take • Gain concepts, plans and mechanisms for creating better software CSE 326 Autumn 2001 7
Still not convinced? Mastery of this material separates you from … CSE 326 Autumn 2001 8
Course Goals • Learn some of the fundamental data structures in computer science • Learn to solve problems abstractly • Data structures are the building blocks • Learn to analyze and improve algorithms • Prove correctness • Gauge and improve time complexity • Learn UNIX • Required in upcoming courses CSE 326 Autumn 2001 9
Prerequisite:Discrete Math • Recall CSE 321 • Proof by induction • Proof by contradiction • Formulas for sums and products of series • Recursion analysis Know Weiss 1.1 – 1.3 by heart! CSE 326 Autumn 2001 10
Preliminary:Unix • Experience 1975 all over again! • Programming Project 1 distributed Monday, Oct 8, but don’t wait … • Try this ASAP • login, edit, create a makefile, compile “Hello, world!” • Bring questions, frustrations to Section on Thursday CSE 326 Autumn 2001 11
Recommendations Check with TAs, course web for guidance Write, debug first without templates Keep it simple - use templates only where most leveraged Pre-compiled (like a macro) Potential source code savings Potential object code bloat Set<int>, Set<char *>, … are each separate classes No compiler fully implements :-( Preliminary:C++ Templates template <class Obj> class Set { public: Insert(Obj x); boolean IsMember(Obj x); } Set<int> SomeNumbers; Set<char *> SomeWords; CSE 326 Autumn 2001 12
Weissvector, string “Smart” alternatives to arrays, char* - adds bounds-checking, memory management Weiss, Appendix B We will use Standard Template Library (STL) Too useful – 326-in-a-box! We will create functional equivalents Weiss, Appendix A Don’t use (unless told) Useful Libraries vector <int> MySafeIntArray; vector <double> MySafeDoubleArray; string MySafeString; CSE 326 Autumn 2001 13
Concepts, Plans, Mechanisms Concepts • A list that lets me store and retrieve things • A tree that lets me store and retrieve things by hierarchy • A table that lets me store and retrieve things by name • A graph (network) that represents distances between cities, relationships between people, tasks within a project, etc. • and so on … CSE 326 Autumn 2001 14
Concepts, Plans, Mechanisms Plans • Pseudocode • Block Diagrams • Flowcharts Mechanisms • Working code Intuition is the bridge concepts plans mechanisms CSE 326 Autumn 2001 15
Learning Concepts vs. Learning Code CSE 326 balances concepts with mechanisms • Grade is 75% concepts and plans, 25% coding skill, but … • Coding greatly improves grasp of concepts and plans Different approaches • Weiss is code-centric: emphasizes plans, mechanisms • Introduction to Algorithms by Cormen, Leiserson, Rivest is pseudocode-centric: emphasizes concepts, plans • The Art of Computer Programming (1968-1973) by Donald Knuth emphasizes concepts, plans, mechanisms • Examples in assembly language (and English)! • American Scientist ranks in top 12 books of century! • Many, many more! CSE 326 Autumn 2001 16
Abstract Data Type (ADT) • Mathematical description of an object and its set of operations ADT typically known only by its exposed operations • ADT is a concept • C++ class is a mechanism for instantiating the ADT concept (and far from the only one) CSE 326 Autumn 2001 17
Data structures Lists, Stacks, Queues Heaps Binary Search Trees AVL Trees Hash Tables Graphs Disjoint Sets Algorithms Insert Delete Find Merge Shortest Paths Union ADT Examples CSE 326 Autumn 2001 18
Asymptotic Complexity How the running time of an algorithm scales with the size of its input Ways to measure complexity • Worst case • Average case • Amortized over a series of (presumably representative) runs CSE 326 Autumn 2001 19
Apocalyptic Laptop Seth Lloyd, a physicist at the Massachusetts Institute of Technology, has calculated how to make PCs almost unimaginably faster--if you don't mind working on a black hole.Lloyd has used the laws of thermodynamics, information, relativity, and quantum mechanics to figure out the ultimate physical limits on the speed of a computer… Lloyd's ultimate laptop would convert all of its 1-kilogram mass into energy via Einstein's famous equation E = mc2, thus turning itself into a billion-degree blob of plasma. "This would present a packaging problem," Lloyd admits … The computer would be capable of performing 1051 operations per second. - Charles Seife, Science Magazine, Vol 289, No 5484, Sep 1 2000, pp. 1447-1448 CSE 326 Autumn 2001 20
Big Bang ApocaLap, 1 year ApocaLap, 1 sec 1000 MIPS since Big Bang 1000 MIPS, 1 day CSE 326 Autumn 2001 21
Max Sum Subsequence (MSS) Given an array of numbers, find the subsequence with maximum sum Example: -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 CSE 326 Autumn 2001 22
MSS: Brute Force Sum -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 -7 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 4 … … -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 21 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 -1 MaxSum 0 while (Subsequences remain) subseq NextSubsequence() if Sum(subseq) > MaxSum MaxSum Sum(subseq) return MaxSum • Consider: • How many subsequences? • How much work is Sum(subseq)? CSE 326 Autumn 2001 23
MSS: Intuition How could we do this in a single pass? • Track subsequence sums as we go • Preserve best we have seen so far • Compare current with best at each stage • Avoid back-tracking Helpful mechanism: structSubseqInfo {lower, upper, sum} 1 3 14 CSE 326 Autumn 2001 24
MSS: Elegance current best 0 -1 0 0 -1 0 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 1 0 0 0 -1 0 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 1 1 3 1 1 3 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 1 2 13 1 2 13 -7 3 10 1 -13 16 -2 -1 4 -7 -5 -5 22 -1 1 3 14 1 3 14 MaxSumSubsequence(A) current {0,-1,0} best current do while loop return best while (++current.Upper < A.Size) current.Sum += A[current.Upper] if current.Sum > best.Sum best current else if current.Sum < 0 current.Lower current.Upper + 1 current.Sum 0 CSE 326 Autumn 2001 25
To Do • Sign up on CSE 326 mailing list • Check out course web • Log onto PC in course lab, access UNIX server, create “Hello, world!” • Read Chapters 1 and 2 in Weiss Poll: Thursday Section topic? CSE 326 Autumn 2001 26