CSI33 Data Structures

Similar documents
CSI33 Data Structures

Core Mathematics 1 Indices & Surds

Unit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.

CSI33 Data Structures

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

Section A Arithmetic ( 5) Exercise A

CSI32 Object-Oriented Programming

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

(Type your answer in radians. Round to the nearest hundredth as needed.)

CSI33 Data Structures

Creating a new data type

Rational number operations can often be simplified by converting mixed numbers to improper fractions Add EXAMPLE:

COMPSCI 105 S Principles of Computer Science. Classes 3

Repeat or Not? That Is the Question!

CSI33 Data Structures

6.3 ADDING and SUBTRACTING Rational Expressions REVIEW. When you ADD rational numbers (fractions): 1) Write each number with common denominator

MAT 142 College Mathematics. Module ST. Statistics. Terri Miller revised July 14, 2015

Integers and Rational Numbers

Watkins Mill High School. Algebra 2. Math Challenge

CSI33 Data Structures

CSI33 Data Structures

What is a Fraction? Fractions. One Way To Remember Numerator = North / 16. Example. What Fraction is Shaded? 9/16/16. Fraction = Part of a Whole

Radical Expressions LESSON. 36 Unit 1: Relationships between Quantities and Expressions

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Adding and subtracting rational expressions is quite similar to adding and subtracting rational numbers (fractions).

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

CSI33 Data Structures

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

Question. What is a fraction? Answer: A topic that scares many of our students

1. Let n be a positive number. a. When we divide a decimal number, n, by 10, how are the numeral and the quotient related?

( 3) ( 4 ) 1. Exponents and Radicals ( ) ( xy) 1. MATH 102 College Algebra. still holds when m = n, we are led to the result

A. Incorrect! To simplify this expression you need to find the product of 7 and 4, not the sum.

The Bracket Strategy

Writing a Fraction Class

Classes, part Deux. Three Groups. CSE 231, Rich Enbody. Users Programmers Class Designers 11/11/13. Michigan State University CSE 231, Fall 2013

2.Simplification & Approximation

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

EE 109 Lab 8a Conversion Experience

Reteaching. Comparing and Ordering Integers

University of Dublin

Rational numbers as decimals and as integer fractions

Math 083 Final Exam Practice

College Prep Algebra II Summer Packet

Unit 2: Accentuate the Negative Name:

Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left

Rational Numbers CHAPTER Introduction

EXAMPLE 1. Change each of the following fractions into decimals.

DATA ABSTRACTION 4. September 25, 2014

1. To add (or subtract) fractions, the denominators must be equal! a. Build each fraction (if needed) so that both denominators are equal.

Vocabulary: Looking For Pythagoras

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

4.3 Rational Thinking

Fractions. Dividing the numerator and denominator by the highest common element (or number) in them, we get the fraction in its lowest form.

Chapter 1 Section 1 Solving Linear Equations in One Variable

Section 1.8. Simplifying Expressions

Priority Queues and Heaps (continues) Chapter 13: Heaps, Balances Trees and Hash Tables Hash Tables In-class Work / Suggested homework.

Structure and Interpretation of Computer Programs

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November COMP1730 / COMP6730 Programming for Scientists

Constructors.

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Q1: Functions / 33 Q2: Arrays / 47 Q3: Multiple choice / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Table of Laplace Transforms

Activity 1: Introduction

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

VALLIAMMAI ENGINEERING COLLEGE

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

CS450 - Structure of Higher Level Languages

DATA ABSTRACTION 5. February 21, 2013

Section 2.3 Rational Numbers. A rational number is a number that may be written in the form a b. for any integer a and any nonzero integer b.

CIT 590 Homework 6 Fractions

Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10.

5.5 Complex Fractions

Fun with Floats. Chapter Never test equality on floats. Fun with Floats

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter Lab 8 - Structures

Object Oriented Programming

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

KNOWLEDGE OF NUMBER SENSE, CONCEPTS, AND OPERATIONS

CS2102, B11 Exam 1. Name:

Algebra 2 Common Core Summer Skills Packet

What is an algorithm?

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

CSI33 Data Structures

Priority Queue ADT. Revised based on textbook author s notes.

Intro to Rational Expressions

1. Let be a point on the terminal side of θ. Find the 6 trig functions of θ. (Answers need not be rationalized). b. P 1,3. ( ) c. P 10, 6.

Outline. Outline. 1 Chapter 2: Data Abstraction

Final Exam MAT 100 JS 2018

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Lesson 4.02: Operations with Radicals

TOPIC 2 DECIMALS (and INTRODUCTION TO FRACTIONS) WEEK 3

Converting between Percents, Decimals, and Fractions

ST MARY S COLLEGE FORM ONE COURSE OUTLINE MATHEMATICS. Term 1. Addition and subtraction. Multiplication and division facts

or 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.

50 MATHCOUNTS LECTURES (6) OPERATIONS WITH DECIMALS

ADDING AND SUBTRACTING RATIONAL EXPRESSIONS

Lecture 19. Operators and Abstraction

Rational Numbers: Multiply and Divide

Types, lists & functions

Transcription:

Outline Department of Mathematics and Computer Science Bronx Community College September 6, 2017

Outline Outline 1 Chapter 2: Data Abstraction

Outline Chapter 2: Data Abstraction 1 Chapter 2: Data Abstraction

The Process of OOD Guidelines Look for object candidates. Use nouns from the problem statement which can be represented by a specific set of information items. Identify instance variables. Choose the specific types of information an object will need to be useful in solving the problem. Think about interfaces. Choose enough methods to completely express the behavior of an object. Refine the nontrivial methods. Continue to use top-down design: add new methods or classes to implement details of methods as you design them.

The Process of OOD Guidelines Design iteratively. Revise higher levels of abstraction if lower level strategies change. Try out alternatives.when an idea can t be made to work, try another. Keep it simple. Programming is complicated enough. Try to reuse code and existing classes to control complexity. Use abstraction to hide the details of a method so you don t have to think about it when working on some other part of the system. Always give names to new classes, methods, and attributes which are descriptive.

Identifying an ADT (Dataset) Problem A program that takes a set of exam scores as input and prints a report that summarizes student performance. from the Textbook, Chapter 1 (Details: The report will give the maximum, minimum, and average of the scores, and the standard deviation.)

Identifying an ADT (Dataset) Objects A score is a number (float, in Python). A set of scores is called a Dataset by statisticians.

Identifying an ADT (Dataset) Methods min returns the lowest score. max returns the highest score. average returns the mean of all the scores. std deviation returns the standard deviation. size returns the size of the Dataset. add adds a new score to the Dataset. init creates a new, empty Dataset.

Implementing the ADT (Dataset) Concrete Representation #1 Attributes: A list object of float values (using classes built in to the Python language). The implementations of the methods specified for the interface will use this information.

Implementing the ADT (Dataset) Concrete Representation #1 Methods: add appends a float value to the list. size returns the length of the list. max, min, average, std deviation perform calculations and return values.

Implementing the ADT (Dataset) Concrete Representation #2 Attributes: average, min, max, size, keep the values that are returned by the methods of the interface. sum, sum squares keep values needed to calculate average and standard deviation values.

Implementing the ADT (Dataset) Concrete Representation #2 Methods: add adds a new float value by calculating and updating all attributes. size returns self. size. max, min, average return their respective attribute values. std deviation returns the standard deviation of the Dataset based on this formula: xi 2 ( x i ) 2. s = n 1 n

Implementing the ADT (Dataset) Comparing Representations While #1 is easier to develop, using top-down design, it loses in comparison with #2 in two critical areas: Space efficiency: the Dataset objects in #2 take up less space, since it does not hold the entire list of float values, only the vital statistics of the data set. Time efficiency: in #1, each method must loop over the entire list of values to calculate and return the statistics. This gives performance of O(n), or more precisely, Θ(n). In #2, statistics are already available as attribute values to be returned immediately, giving performance of O(1) (indeed, Θ(1)).

Identifying the ADT Problem Python has no way to represent the values of certain fractions such as 1 3 exactly because the denominator is not a power of two. Yet there are simple rules to add, subtract, multiply and divide fractions exactly. Design a class to implement operations on exact rational numbers.

Operator Overloading Operations in Existing Python Classes Python allows addition of integers using different syntactic forms: >>> a = 3 >>> a+4 7 >>> a. add (4) 7 >>> int. add (a, 4) 7

Operator Overloading Adapting Existing Operations for New Classes Similar examples can be given for most other binary operations. To bring these operations to new classes, define appropriately named methods, with appropriate behavior, returning objects having the desired value. For example: class Rational(object):... def add (self, other):... return Rational(num,den) will allow a+b to have the correct rational value if a and b are Rational objects.

The Rational Class Concrete Representation Attributes: num (integer, numerator) den (integer greater than zero, denominator)

The Rational Class Concrete Representation Methods: Constructor init (self, n, d) Overloaded operators, using add, sub, et cetera.