Study Guides (248,610)
Canada (121,635)
CS 234 (11)
Final

midterm_final review notes.docx

20 Pages
212 Views

Department
Computer Science
Course Code
CS 234
Professor
Kevin Lanctot

This preview shows pages 1,2,3,4. Sign up to view the full 20 pages of the document.
Description
CS234MidtermFinalExamReviewList Slicingx2 takes the first two elements of xx2 takes all but the first two element of xEx aListlenaList2aListlenaList2a 12345lenaList5522flipFlopa3 4 5 1 2Exceptions an event that can be triggered and optionally handled during program executionraise an exception when error occurswhen exception raise an error program can catch the exception and handle itwhen exception is not handled program will abort an error ie IndexError list out of rangeCatching ExceptionTypeError raised when an incorrect data type is supplied to an operatorValueError raised when is a correct data type but wrong valueAssertionError aasert what we assume to be true at a given point in the programdifference between Exception and Assert assert can deactivated at run timeData type is how to interpret the data Simple ADT a single or several individual represent a data or number ie Node bool int floatComplex ADT a collection of data valuesie string list tuple range dictionary setData Structure store a collection of values but different in how it organize the individual data and by what operations can be applied to manage the collectionie Array linked list stack queue treeex queue structure is better for implementing a printer queueex BTree is better for a databases indexAbstraction means capture the relevantimportant aspects focus on what is done Procedural Abstraction use a function without knowing the details of how it is written Data Abstraction use data types without knowing the details of how they are implementedAbstract Data Type ADT programmerdefined data type that specifies a set of data values and a collection of welldefined operations that can be performed on those valuesAre defined independentWhy use Abstract Data Types Focus on basic operations and the use of data instead of lowlevel implementation details Prevent errors by limiting controlling the use of implementation details how the type can be used Implementation can be updated without changing programs using the ADT Easier to manage large projects by breaking them down into smaller modulesPreconditions and Postconditions identify from the description of ADT functionPrecondition condition of an input before a function can be performedAssume to be true while postcondition is guarantee as long as preconditions are metassumptions the implementer of a function can make while implementing itIf precondition is not satisfied should raise error exceptionEx in division with integers abPrecondition b is nonzeroEx for mathsqrtx with floatsPrecondition x is nonnegativeEx type is it a float and raising a TypeError exception if it is notEx value is it nonzero and raising a ValueError exception if it is notPostcondition the result of an output after the function is performedSome function may not have postcodition because it simply return a value without modifying the ADT instance itselfhas to guarantee after a function is done as long as the preconditions have been metassumptions the user of a function can make after the function has finishedEX in division with integers abPostcondition the function will return the integer value of how many times b divides a ignoring any remainderselfstocks underscoremeans you should not access this variable outside the
More Less
Unlock Document

Only pages 1,2,3,4 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit