Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ben Lerner Summer Quarter 2007 Lecture 1

Similar presentations


Presentation on theme: "Ben Lerner Summer Quarter 2007 Lecture 1"— Presentation transcript:

1 Ben Lerner Summer Quarter 2007 Lecture 1
CSE 326: Data Structures Ben Lerner Summer Quarter 2007 Lecture 1

2 CSE 326 Crew Instructor: Ben Lerner, CSE 212 TAs: Office hours: TBD
TAs: Ioannis Giotis Gyanit Singh Office hours: TBD (Introduce everyone) “ give them a hand” 1/2/2019 CSE Introduction

3 Today’s Outline Introductions Administrative Info
What is this course about? Review: Queues and stacks 1/2/2019 CSE Introduction

4 Course Information Text: Data Structures & Algorithm Analysis in Java, (Mark Allen Weiss), 1999 Web page: (will be available soon) Mailing Lists: announcement list: Subscribe to this using web interface, see homepage Discussion list: link on course home page (Coming soon!) Announce is required. 1/2/2019 CSE Introduction

5 Course Mechanics Written homeworks (8 total)
Due at the start of class on due date No late homeworks accepted Programming homeworks (3 total, with phases) In Java Turned in electronically and on paper Can have one “late day” for extra 24 hours – Must TA in advance Work in teams only on explicit team projects Appropriate discussions encouraged – see website Gilligan’s Island rule applies 1/2/2019 CSE Introduction

6 Course Mechanics Approximate Grading
25% - Written Homework Assignments 25% - Programming Assignments 20% - Midterm Exam (in class, fifth week) 30% - Final Exam (last day of class) 1/2/2019 CSE Introduction

7 Project/Homework Guides
On the website - note especially Homeworks: use pseudocode, not code. A human being is reading your homeworks See website for pseudocode examples Projects: execution is only 40% of your grade! Spend time commenting your code as you write - it will help you be a better programmer 1/2/2019 CSE Introduction

8 Homework for Today!! Sign up for mailing list (immediately)
Project #1: Implement stacks and queues (due in 1 week) Reading in Weiss Chapter 1 – (review) Mathematics and Java Chapter 3 – (Project #1) Lists, Stacks, & Queues Chapter 2 – (Topic for Friday) Algorithm Analysis Homework #1: based off reading, handed out next class See course web page for more on both of these 1/2/2019 CSE Introduction

9 Project 1 Soundblaster! Reverse a song
Implement a stack and a queue to make the “Reverse” program work Read the website Detailed description of assignment Detailed description of how programming projects are graded 1/2/2019 CSE Introduction

10 Today’s Outline Introductions Administrative Info
What is this course about? Review: Queues and stacks 1/2/2019 CSE Introduction

11 Class Overview Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know when to apply them Practice design and analysis of data structures. Practice using these data structures by writing programs. Make the transformation from programmer to computer scientist 1/2/2019 CSE Introduction

12 Goal You will understand So that you can You will be able to
what the tools are for storing and processing common data types which tools are appropriate for which need So that you can make good design choices as a developer, project manager, or system customer You will be able to Justify your design decisions via formal reasoning Communicate ideas about programs clearly and precisely 1/2/2019 CSE Introduction

13 Data Structures “Clever” ways to organize information in order to enable efficient computation What do we mean by clever? What do we mean by efficient? clever – range from techniques with which you are already familiar – eg, representing simple lists – to ones that are more complex, such as hash tables or self-balancing trees. Elegant, mathematically deep, non obvious. making the different meanings of “efficient” precise is much of the work of this course! 1/2/2019 CSE Introduction

14 Picking the best Data Structure for the job
The data structure you pick needs to support the operations you need Ideally it supports the operations you will use most often in an efficient manner Examples of operations: A List with operations insert and delete A Stack with operations push and pop 1/2/2019 CSE Introduction

15 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 family of algorithms for implementing an abstract data type. Implementation of data structure A specific implementation in a specific language 1/2/2019 CSE Introduction

16 Terminology examples A stack is an abstract data type supporting push, pop and isEmpty operations A stack data structure could use an array, a linked list, or anything that can hold data One stack implementation is java.util.Stack; another is java.util.LinkedList 1/2/2019 CSE Introduction

17 Concepts vs. Mechanisms
Abstract Pseudocode Algorithm A sequence of high-level, language independent operations, which may act upon an abstracted view of data. Abstract Data Type (ADT) A mathematical description of an object and the set of operations on the object. Concrete Specific programming language Program A sequence of operations in a specific programming language, which may act upon real data in the form of numbers, images, sound, etc. Data structure A specific way in which a program’s data is represented, which reflects the programmer’s design choices/goals. Note how much messier life becomes when we move from abstract concepts to concrete mechanisms. Being able to abstract the intrinsic problems from the real world scenarios -- or, alternatively, being able to realize an abstract concept in code -- is one of the important skills that computer scientists need to possess. Note that pseudocode is a concept, and a programming language is a mechanism. 1/2/2019 CSE Introduction

18 Why So Many Data 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 What does it mean to be “fast”? What about “elegant”? The study of data structures is the study of tradeoffs. That’s why we have so many of them! 1/2/2019 CSE Introduction

19 Today’s Outline Introductions Administrative Info
What is this course about? Review: Queues and stacks 1/2/2019 CSE Introduction

20 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 Here comes our first instance of this algorithm… You’ve probably seen the Q before. If so, this is an opportunity to get familiar with how we will be presenting algorithms 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. 1/2/2019 CSE Introduction

21 Circular Array Queue Data Structure
size - 1 b c d e f front back How test for empty list? How to find K-th element in the queue? What is complexity of these operations? Limitations of this structure? enqueue(Object x) { Q[back] = x ; back = (back + 1) % size } 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. 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[front] ; front = (front + 1) % size; return x ; } 1/2/2019 CSE Introduction

22 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 } 1/2/2019 CSE Introduction

23 Circular Array vs. Linked List
Too much space Kth element accessed “easily” Not as complex Could make array more robust Can grow as needed Can keep growing No back looping around to front Linked list code more complex LinkedList takes more memory, but no size limitations. LinkedList code a little more complex. May want dummy header node. 1/2/2019 CSE Introduction

24 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 1/2/2019 CSE Introduction

25 Stacks in Practice Function call stack Removing recursion
Balancing symbols (parentheses) Evaluating Reverse Polish Notation 1/2/2019 CSE Introduction

26 Algorithm Analysis: Why?
Correctness: Does the algorithm do what is intended. How well does the algorithm complete its goal Performance: What is the running time of the algorithm. How much storage does it consume. Different algorithms may correctly solve a given task Which should I use? 1/2/2019 CSE Introduction

27 Iterative algorithm for sum
Find the sum of the first n integers stored in an array v. sum(integer array v, integer n) returns integer let sum = 0 for i = 1...n sum = sum + ith number return sum Note the use of pseudocode 1/2/2019 CSE Introduction

28 Recursive algorithm for sum
Write a recursive function to find the sum of the first n integers stored in array v. sum(integer array v, integer n) returns integer if n = 0 then sum = 0 else sum = nth number + sum of first n-1 numbers return sum 1/2/2019 CSE Introduction

29 Proof by Induction Basis Step: The algorithm is correct for a base case or two by inspection. Inductive Hypothesis (n=k): Assume that the algorithm works correctly for the first k cases. Inductive Step (n=k+1): Given the hypothesis above, show that the k+1 case will be calculated correctly. 1/2/2019 CSE Introduction

30 Program Correctness by Induction
Basis Step: sum(v,0) = 0.  Inductive Hypothesis (n=k): Assume sum(v,k) correctly returns sum of first k elements of v, i.e. v[0]+v[1]+…+v[k-1] Inductive Step (n=k+1): sum(v,n) returns v[k]+sum(v,k)= (by inductive hyp.) v[k]+(v[0]+v[1]+…+v[k-1])= v[0]+v[1]+…+v[k-1]+v[k]  1/2/2019 CSE Introduction

31 Algorithms vs Programs
Proving correctness of an algorithm is very important a well designed algorithm is guaranteed to work correctly and its performance can be estimated Proving correctness of a program (an implementation) is fraught with weird bugs Abstract Data Types are a way to bridge the gap between mathematical algorithms and programs 1/2/2019 CSE Introduction


Download ppt "Ben Lerner Summer Quarter 2007 Lecture 1"

Similar presentations


Ads by Google