CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016



Similar documents
Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

DATA STRUCTURES USING C

Chapter 3: Restricted Structures Page 1

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Data Structures and Algorithms Stacks and Queues

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

CS 2302 Data Structures Spring 2015

DATA STRUCTURE - STACK

Module 2 Stacks and Queues: Abstract Data Types

Introduction to Data Structures

7.1 Our Current Model

Analysis of a Search Algorithm

Common Data Structures

Sequential Data Structures

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

Universidad Carlos III de Madrid

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions. Linda Shapiro Spring 2016

DATA STRUCTURE - QUEUE

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Big O and Limits Abstract Data Types Data Structure Grand Tour.

Algorithms and Data Structures Written Exam Proposed SOLUTION

St S a t ck a ck nd Qu Q eue 1

STACKS,QUEUES, AND LINKED LISTS

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Data Structure [Question Bank]

Introduction to Programming System Design. CSCI 455x (4 Units)

Linked Lists Linked Lists, Queues, and Stacks

Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16

Introduction to Data Structures and Algorithms

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Java Software Structures

Sample Syllabus (C++) CSCI 1301 Introduction to Programming Principles

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Data Structures and Algorithms V Otávio Braga

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

CS 300 Data Structures Syllabus - Fall 2014

Algorithms and Data Structures

Cpt S 223. School of EECS, WSU

Lecture 2: Data Structures Steven Skiena. skiena

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

AP Computer Science AB Syllabus 1

Data Structures and Algorithms

Application of Stacks: Postfix Expressions Calculator (cont d.)

Dynamic Programming Problem Set Partial Solution CMPSC 465

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Data Structures. Chapter 8

Stacks. Data Structures and Data Types. Collections

Lecture 1: Course Introduction"

PES Institute of Technology-BSC QUESTION BANK

Node-Based Structures Linked Lists: Implementation

1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: Data Structures

Useful Java Collections

STAT 1403 College Algebra Dr. Myron Rigsby Fall 2013 Section 0V2 crn 457 MWF 9:00 am

CS 301 Course Information

Section IV.1: Recursive Algorithms and Recursion Trees

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

! stack, queue, priority queue, dictionary, sequence, set e.g., a Stack is a list implements a LIFO policy on additions/deletions.

Data Structures and Algorithms Lists

CNT5412/CNT4406 Network Security. Course Introduction. Zhenhai Duan

Multimedia & the World Wide Web

CSE 326: Data Structures B-Trees and B+ Trees

Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

02-201: Programming for Scientists

Programming with Data Structures

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

CMSC 152: Introduction to Computer Science II

Data Structures in the Java API

10CS35: Data Structures Using C

Syllabus MAC1105 College Algebra

269 Business Intelligence Technologies Data Mining Winter (See pages 8-9 for information about 469)

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Computer Science Theory. From the course description:

Lecture Notes on Stacks & Queues

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Math Content by Strand 1

Ordered Lists and Binary Trees

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Introduction to Information Technology ITP 101x (4 Units)

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

Computer Science 210: Data Structures. Introduction

Student Registration for MyMathLab

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

COMPUTER SCIENCE COURSE OUTLINE

CompSci-61B, Data Structures Final Exam

CS 43: Computer Networks Course Introduction. Grab a clicker and please sit towards the front, next to other students!

Transcription:

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro

Registration We have 180 students registered and others who want to get in. If you re thinking of dropping the course please decide soon! Waiting students Please sign up on the paper waiting list after class, so I know who you are. If you need the class to graduate this June, put that down, too. The CSE advisors and I will decide by end of Friday who gets in. 2

Welcome! We have 10 weeks to learn fundamental data structures and algorithms for organizing and processing information Classic data structures / algorithms How to rigorously analyze their efficiency How to decide when to use them Queues, dictionaries, graphs, sorting, etc. Today in class: Introductions and course mechanics What this course is about Start abstract data types (ADTs), stacks, and queues Largely review 3

To-do list In next 24-48 hours: Read the web page Read all course policies Read Chapters 3.1 (lists), 3.6 (stacks) and 3.7 (queues) of the Weiss book Relevant to Homework 1, due next week Set up your Java environment for Homework 1 http://courses.cs.washington.edu/courses/cse373/16sp/ 4

Course staff Linda Shapiro CSE Professor with research in computer vision. Have taught CS&E for 40 years. First course I ever taught was Data Structures. Ezgi Mercan Mert Saglam Ben Jones Shenqi Tang Bran Hagger Chloe Lathe Lysia Li Office hours, email, etc. on course web-page 5

Communication Course email list: cse373a_sp16@u.washington.edu Students and staff already subscribed You must get announcements sent there Fairly low traffic; You don t post there Course staff: cse373-staff@cs.washington.edu plus individual emails Discussion board For appropriate discussions; TAs will monitor Encouraged, but won t use for important announcements Anonymous feedback link For good and bad, but please be gentle. 6

Course meetings Lecture Materials posted, but take notes Ask questions, focus on key ideas (rarely coding details) Optional help sessions Help on programming/tool background Helpful math review and example problems Again, optional but helpful Fill out our online poll for best times Office hours Use them: please visit me for talking about course concepts or just CSE in general. See the TAs for Java programming questions. 7

Course materials All lecture will be posted But they are visual aids, not always a complete description! If you have to miss, find out what you missed Textbook: Weiss 3 rd Edition in Java A good Java reference of your choosing Don t struggle Googling for features you don t understand Constantly skipping class is not good for your grade. 8

Computer Lab College of Arts & Sciences Instructional Computing Lab http://depts.washington.edu/aslab/ Or your own machine Will use Java for the programming assignments Eclipse is recommended programming environment 9

Course Work 5-6 homeworks (50%) Most involve programming, but also written questions Higher-level concepts than just code it up First programming assignment due next week Midterm Week of May 2, in class (20%) Final exam: Tuesday June 7, 2:30-4:20PM (30%) 10

Collaboration and Academic Integrity Read the course policy very carefully Explains quite clearly how you can and cannot get/provide help on homework and projects Always explain any unconventional action on your part When it happens, when you submit, not when asked The CSE Department and I take academic integrity extremely seriously. IF YOU RE NOT SURE, THEN ASK! 11

Some details You are expected to do your own work Exceptions (group work), if any, will be clearly announced Sharing solutions, doing work for, or accepting work from others is cheating Referring to solutions from this or other courses from previous quarters is cheating But you can learn from each other: see the policy 12

What this course will cover Introduction to Algorithm Analysis Lists, Stacks, Queues Trees, Hashing, Dictionaries Heaps, Priority Queues Sorting Disjoint Sets Graph Algorithms Advanced Data Structures and Applications 13

Goals Be able to make good design choices as a developer, project manager, etc. Reason in terms of the general abstractions that come up in all non-trivial software (and many non-software) systems Be able to justify and communicate your design decisions You will learn the key abstractions used almost every day in just about anything related to computing and software. This is not a course about Java! We use Java as a tool, but the data structures you learn about can be implemented in any language. 14

Let s start! 15

Data structures A data structure is a (often non-obvious) way to organize information to enable efficient computation over that information A data structure supports certain operations, each with a: Meaning: what does the operation do/return Performance: how efficient is the operation Examples: List with operations insert and delete Stack with operations push and pop 16

Trade-offs A data structure strives to provide many useful, efficient operations But there are unavoidable trade-offs: Time vs. space One operation more efficient if another less efficient Generality vs. simplicity vs. performance We ask ourselves questions like: Does this support the operations I need efficiently? Will it be easy to use (and reuse), implement, and debug? What assumptions am I making about how my software will be used? (E.g., more lookups or more inserts?) 17

Terminology Abstract Data Type (ADT) Mathematical description of a thing with set of operations Not concerned with implementation details Algorithm A high level, language-independent description of a step-bystep process Data structure A specific organization of data and family of algorithms for implementing an ADT Implementation of a data structure A specific implementation in a specific language 18

Example: Stacks The Stack ADT supports operations: isempty: have there been same number of pops as pushes push: adds an item to the top of the stack pop: raises an error if empty, else removes and returns most-recently pushed item not yet returned by a pop What else? top (java peek) A Stack data structure could use a linked-list or an array and associated algorithms for the operations One implementation is in the library java.util.stack 19

Why useful The Stack ADT is a useful abstraction because: It arises all the time in programming (e.g., see Weiss 3.6.3) Recursive function calls Balancing symbols in programming (parentheses) Evaluating postfix notation: 3 4 + 5 * Clever: Infix ((3+4) * 5) to postfix conversion (see text) We can code up a reusable library We can communicate in high-level terms Use a stack and push numbers, popping for operators Rather than, create an array and keep indices to the 20

Stack Implementations stack as a linked list TOP NULL TOP a TOP b a stack as an array TOP=-1 TOP=0 a TOP=1 a b 21

The Queue ADT Operations create destroy enqueue dequeue is_empty What else? front G Just like a stack except: enqueue (IN) Stack: LIFO (last-in-first-out) Queue: FIFO (first-in-first-out) Back F E D C B Front dequeue (OUT) A 22

Stacks vs. Queues Stack Queue 23

Circular Array Queue Data Structure Q: 0 size - 1 b c d e f front back // Basic idea only! enqueue(x) { next = (back + 1) % size Q[next] = x; back = next } // Basic idea only! dequeue() { x = Q[front]; front = (front + 1) % size; return x; } x next What if queue is empty? Enqueue? yes Dequeue? no What if array is full? Enqueue? no Dequeue yes 24

Circular Array Example (text p 94 has another one) OUT IN g front enqueue( g ) o1 = dequeue( ) b o2 = dequeue( ) c o3 = dequeue( ) d o4 = dequeue( ) e o5 = dequeue( ) f o6 = dequeue( ) g Now where are back and front? Now front = back+1! 25

Empty Queue Will front = back + 1 always be true for an empty queue? back front -1 0 back front 4 4 a b c d e 0 0 a 4 0 a b c d e 4 0 a b c d e front = (back + 1) % arraysize 0 = 5 % 5 26

Circular Queue When we add an f to the queue that has only the e, back will go around to position zero. back=(4+1)%5 back front -1 0 back front 4 4 a b c d e 0 0 a 0 4 f b c d e 4 0 a b c d e 27

Complexity of Circular Queue Operations // Basic idea only! enqueue(x) { next = (back + 1) % size Q[next] = x; back = next } O(1) constant // Basic idea only! dequeue() { x = Q[front]; front = (front + 1) % size; return x; } O(1) constant 28

Linked List Queue Data Structure b c d e f front // Basic idea only! enqueue(x) { back.next = new Node(x); back = back.next; } // Basic idea only! dequeue() { x = front.item; front = front.next; return x; } back What if queue is empty? Enqueue? yes Dequeue? no Can list be full? no How to test for empty? front=back=null What is the complexity of the operations? O(1) 29

Circular Array vs. Linked List for Queues Array: May waste unneeded space or run out of space Space per element excellent Operations very simple / fast Constant-time access to k th element List: Always just enough space But more space per element Operations very simple / fast No constant-time access to k th element For operation insertatposition, must shift all later elements Not in Queue ADT For operation insertatposition must traverse all earlier elements Not in Queue ADT This is stuff you should know after being awakened in the dark 30

Conclusion Abstract data structures allow us to define a new data type and its operations. Each abstraction will have one or more implementations. Which implementation to use depends on the application, the expected operations, the memory and time requirements. Both stacks and queues have array and linked implementations. We ll look at other ordered-queue implementations later. 31