This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Welcome to CS 136 (Spring 2011) Instructor: Mark Petrick Tutors: Stuart Rudderham, Sunny Wu Instructional Assistants (IAs): Lesley Northam, Caelyn McAulay Web page (main information source): http://www.student.cs.uwaterloo.ca/cs136/ Lectures: 1 section, each Tuesday and Thursday Tutorials: 2 sections on Mondays CS 136 Spring 2011 01: Introduction to CS 136 1 Textbooks: How to Design Programs (HtDP) by Felleisen, Flatt, Findler, Krishnamurthi ( http://www.htdp.org ) and C Programming: A Modern Approach (CP:AMA) by K. N. King. Presentation handouts: available on Web page Marking Scheme: 25% assignments (weekly), 30% midterm, 45% final exam + bonus Your assignment average and weighted exam average must both be greater than 50% Software: RunC will be used for Racket/Scheme and C CS 136 Spring 2011 01: Introduction to CS 136 2 Where to begin? Time and Space Complexity An Idea Type (ADT) Abstract Data (Racket, C, ...) Code Specification Implementation Analysis CS 136 Spring 2011 01: Introduction to CS 136 3 An Idea 18 4 22 add remove A collection of items such that: We can add an item to the collection We keep track of the order in which items were added The item that was added most recently is the only one that can be seen or removed We can see if there is at least one item in the collection CS 136 Spring 2011 01: Introduction to CS 136 4 Abstract Data Types (ADTs) This idea can be precisely described as an Abstract Data Type (ADT) An ADT specifies two things: The type of data that is stored A set of operations that can be performed on the data This specification does not depend on any specific programming language CS 136 Spring 2011 01: Introduction to CS 136 5 ADT Stack Our idea is called a Stack The type of data is described as a sequence of items [ a 1 ,a 2 ,...,a n ] such that n CS 136 Spring 2011 01: Introduction to CS 136 6 We will allow the following five operations: Make an empty stack ( makestack ) Add an item to the top of a stack ( push ) Remove an item from the top of a stack ( pop ) Look at the item at the top of a stack ( peek ) Check if the stack is empty ( stackempty? ) However, these descriptions are not precise CS 136 Spring 2011 01: Introduction to CS 136 7 Specification of Operations For each ADT operation, we must specify: The parameters (if any) Preconditions: What must be true before performing this operation? Postconditions: Assuming the preconditions have been satisfied, what will be true after the operation has been performed? What will happen if the preconditions of an operation are not satisfied? CS 136 Spring 2011 01: Introduction to CS 136 8 Specification of Stack Operations makestack Parameters: None Pre: True (i.e. there are no preconditions) Post: The empty stack S = is produced push Parameters: An item x and a stack S = [ a 1 ,...,a n ] , n Pre: True Post: The stack S = [ x,a 1 ,...,a n ] is produced CS 136 Spring 2011 01: Introduction to CS 136 9 Implementation of an ADT...
View
Full
Document
 Spring '08
 BECKER

Click to edit the document details