Spring 2016 Richard Anderson Lecture 1

Slides:



Advertisements
Similar presentations
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Advertisements

 Balancing Symbols 3. Applications
Come up and say hello! 1. CPSC 221: Algorithms and Data Structures Lecture #0: Introduction Steve Wolfman 2009W1 2.
Administrivia- Introduction CSE 373 Data Structures.
CSE 326: Data Structures Lecture #0 Introduction Steve Wolfman Winter Quarter 2000.
CSE 326: Data Structures Lecture #0 Introduction Bart Niswonger Summer Quarter 2001.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Lauren Milne Summer 2015.
Computer Science 102 Data Structures and Algorithms V Fall 2009 Lecture 1: administrative details Professor: Evan Korth New York University 1.
CSE332: Data Abstractions Lecture 1: Introduction; Stacks/Queues Tyler Robison Summer 2010.
CSCA48 Course Summary.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Come up and say hello! 1. CPSC 221: Algorithms and Data Structures Lecture #0: Introduction Steve Wolfman 2010W2 2.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Kevin Quinn Fall 2015.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Catie Baker Spring 2015.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Winter 2015.
April 27, 2017 COSC Data Structures I Review & Final Exam
Data Structures and Algorithms in Java AlaaEddin 2012.
CSE 326 More Lists, Stacks and Queues David Kaplan Dept of Computer Science & Engineering Autumn 2001.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Spring 2016.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Hunter Zahn Summer 2016 CSE373: Data Structures and Algorithms1.
CSE373: Data Structures & Algorithms Priority Queues
Review Array Array Elements Accessing array elements
CSE373: Data Structures and Algorithms
CSE373: Data Structures & Algorithms
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
COSC160: Data Structures: Lists and Queues
September 29 – Stacks and queues
March 27 – Course introductions; Adts; Stacks and Queues
Chapter 15 Lists Objectives
March 29 – Testing and Priority QUeues
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Queues Queues Queues.
Week 15 – Monday CS221.
March 31 – Priority Queues and the heap
Computer Science 102 Data Structures CSCI-UA
September 27 – Course introductions; Adts; Stacks and Queues
Cse 373 April 26th – Exam Review.
Lecture 1: Welcome to CSE 373
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Lecture 2: Implementing ADTs
Lecture 2: Implementing ADTs
Stacks, Queues, and Deques
Lesson Objectives Aims
Introduction CSE 373 Data Structures.
Stacks and Queues CSE 373 Data Structures.
Ben Lerner Summer Quarter 2007 Lecture 1
Stacks and Queues CLRS, Section 10.1.
Stacks and Queues 1.
Stacks and Queues Prof. Michael Tsai 2017/02/21.
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Administrivia- Introduction
Stacks and Queues CSE 373 Data Structures.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Administrivia- Introduction
CSE 373 Data Structures Lecture 6
Instructor: Dr. Michael Geiger Spring 2019 Lecture 34: Exam 3 Preview
structures and their relationships." - Linus Torvalds
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
DATA STRUCTURES IN PYTHON
Presentation transcript:

Spring 2016 Richard Anderson Lecture 1 CSE 332: Data Structures Spring 2016 Richard Anderson Lecture 1

CSE 332 Team Instructors: Richard Anderson TAs: Hunter Zahn, Andrew Li anderson at cs TAs: Hunter Zahn, Andrew Li hzahn93 at cs lia4 at cs (Introduce everyone) “ give them a hand”

Today’s Outline Introductions Administrative Info What is this course about? Review: queues and stacks

Course Information http://www.cs.washington.edu/332 Weiss, Data Structures & Algorithm Analysis in Java, 3nd Edition, 2012. (or buy 2nd edition—1/3 price on Amazon!) Announce is required. 3rd edition ~ $150 2nd edition ~ $45, or $3 used…

Communication Staff Announcements cse332-staff@cs.washington.edu (or our individual addresses) Announcements cse332a_sp16@u (you are automatically subscribed @u)

Written homeworks Written homeworks (8 total) Assigned weekly Due at the start of class on due date No late homeworks accepted

Projects Programming projects (3 total, some with phases) In Java Eclipse encouraged Turned in electronically Work on individually Start work early You have two to three weeks on the projects They are going to be very hard to get done in two to three days Issue to watch out for: Java generics

Project 1 out today

Overall grading Grading 20% - Written Homework Assignments 30% - Programming Assignments 20 % - Midterm Exam (Apr 29) 30% - Final Exam (June 6, 2:30-4:20 pm)

Collaboration HWs and Projects must be done solo But you can discuss problems with others as long as you follow the Gilligan’s island rule

Section Meet on Thursdays What happens there? Answer questions about current homework Previous homeworks returned and discussed Discuss the project (getting started, getting through it, answering questions) Finer points of Java, eclipse, etc. Reinforce lecture material

Homework for Today!! Reading in Weiss Chapter 1 – (Review) Mathematics and Java Chapter 2 – (Next lecture) Algorithm Analysis Chapter 3 – (Project #1) Lists, Stacks, & Queues See course web page for more on both of these

Today’s Outline Introductions Administrative Info What is this course about? Review: Queues and stacks

Common tasks Many possible solutions Choice of algorithm, data structures matters What properties do we want? Solving these problems requires:  algorithm, data structures Choice of alg/ds can make a huge difference (seconds vs. days) Desiderada: speed, small memory, elegance/simplicity Why does elegance matter? Easier to debug, maintain. Often these things are at odds—can’t always have all three, but sometimes you can. Usually, the first thing you think of is much slower than the best performing method People have written PhD theses on memory allocation, sorting algorithms, etc. Some of these methods are very complex, some are simple and elegant—we’ll be focusing on the latter… speed, small memory, elegance/simplicity Why does elegance matter? Easier to debug, maintain. Often these things are at odds—can’t always have all three, but sometimes you can.

Why should we care? Computers are getting faster No need to optimize Libraries: experts have done it for you Computers are getting faster: no need to optimize? there’s some truth to this—many optimizations no longer matter But usually it does matter—problem sizes are getting much bigger - examples: hard disk—terrabytes! (my first mac had 10M disk). No more Moore’s law for CPUs… Libraries: experts have done this for you How do you know which routine to call? What if the alg you need isn’t there? Computers are getting faster no need to optimize Some truth to this—many optimizations no longer matter. But problem size are bigger (terrabytes!) No more Moore’s law for CPU’s Libraries—experts have done the hard work for you. But—which routine to call? What if alg isn’t there?

Program Abstraction Problem defn: Algorithm: Implementation: Sort N numbers Sort N number Alg: quick sort, insertion sort, bubble sort… Imp: quickSort.java quickSort.C ? Quicksort, insertion sort… quickSort.java, quickSort.c, …

Data Abstraction Abstract Data Type (ADT): Data Structure: Implementation: Stack -> ? push, pop, isEmpty ADT: Stack  push, pop, isEmpty DataStructure: linked list, array Implementation: java.util.Stack, java.util.LinkedList ? Linked list, array, … java.util.Stack, java.util.LinkedList

Terminology Abstract Data Type (ADT) Algorithm Data structure Mathematical description of an object with set of operations on the object. Useful building block. Algorithm A high level, language-independent, description of a step-by-step process. Data structure A specific organization of the data to accompany algorithms for an abstract data type. Implementation of data structure A specific implementation in a specific language.

A starting problem: Prefix Sum Input: Array arr of size n Methods: arr.sum(i) – find the sum of arr[0]…arr[i] arr.update(i, value) – update arr[i] to value

Solutions Naïve Prefix array arr.sum(i): Loop through and add values arr.update(i, value): arr[i] = value; Prefix array Compute pre[i] = arr[0] + . . . + arr[i] for all i arr.sum(i): return pre[i] arr.update(i, value): recompute prefix array

Examples Naïve: Prefix Array: 1 3 -4 6 3 5 -4 9 1 3 -4 6 3 5 -4 9 1 4 6 9 14 10 19

Better solution: Tree of partial sums 1 3 -4 6 3 5 -4 9 19 6 13 4 2 8 5 1 3 -4 6 3 5 -4 9

Sum and Update in O(log n) time 19 6 13 4 2 8 5 1 3 -4 6 3 5 -4 9

Today’s Outline Introductions Administrative Info What is this course about? Review: queues and stacks

First Example: Queue ADT FIFO: First In First Out Queue operations create destroy enqueue dequeue is_empty F E D C B enqueue dequeue G A You’ve probably seen the Q before. If so, this is an opportunity to get familiar with how we will be treating concepts in this class. If not, then the Q is a simple but very powerful abstraction, and you should make sure you understand it thoroughly. Note the lack of any implementation details – just the interface and key properties that must be satisfied.

Queues in practice Print jobs File serving Phone calls and operators (Later, we will consider “priority queues.”)

Array Queue Data Structure size - 1 Q b c d e f back enqueue(Object x) { Q[back] = x back = (back + 1) } What’s missing in these functions? How to find K-th element in the queue? Here is a data structure implementation of the Q. The queue is stored as an array. shiftLeftOne is expensive! 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! dequeue() { x = Q[0] shiftLeftOne() Back = (back – 1) return x }

Circular Array Queue Data Structure size - 1 Q b c d e f enqueue(Object x) { assert(!is_full()) Q[back] = x back = (back + 1) } front back How test for empty/full list? How to find K-th element in the queue? What to do when full? dequeue() { assert(!is_empty()) x = Q[front] front = (front + 1) return x } Here is another 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. Test for empty/full: front = back Can we do something smarter when full?

Linked List Queue Data 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 } bool is_empty() { return front == null Object dequeue() { assert(!is_empty()) return_data = front->data temp = front front = front->next delete temp return return_data }

Circular Array vs. Linked List Advantages of circular array? Advantages of linked list? Advantage of circular array? Faster (except for resize), simpler memory management Advantage of linked list? No max size (or need to reallocate/copy) - unused space, resizing + faster indexing + memory coherence + can grow as needed - slow indexing

Second Example: Stack ADT LIFO: Last In First Out Stack operations create destroy push pop top is_empty A B C D E F E D C B A F

Stacks in Practice Function call stack Removing recursion Balancing symbols (parentheses) Evaluating postfix or “reverse Polish” notation

Assigned readings Reading in Weiss Chapter 1 – (Review) Mathematics and Java Chapter 2 – (Next lecture) Algorithm Analysis Chapter 3 – (Project #1) Lists, Stacks, & Queues