Warmup. A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.

Similar documents
Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

Lists, Stacks, and Queues (plus Priority Queues)

REVIEW SHEETS BASIC MATHEMATICS MATH 020

Mathematics (MEI) Advanced Subsidiary GCE Core 1 (4751) May 2010

6.N.3 Understand the relationship between integers, nonnegative decimals, fractions and percents.

Chapter 2. Polynomial and Rational Functions. 2.5 Zeros of Polynomial Functions

Solutions 2017 AB Exam

Archdiocese of Washington Catholic Schools Academic Standards Mathematics

Mathematics (MEI) Advanced Subsidiary GCE Core 1 (4751) June 2010

2. Polynomials. 19 points. 3/3/3/3/3/4 Clearly indicate your correctly formatted answer: this is what is to be graded. No need to justify!

Today is Thursday, February 8 th, 2018

27 2 x 1 = Solve the equation. Check your solution. 5. Solve the equation. Check your solution. 7. Solve the equation. Check your solution.

Algebra 2 and Trigonometry

Academic Outcomes Mathematics

Intermediate Level Learning Targets

9.1 HW (3+3+8 points) (Knapsack decision problem NP-complete)

MATH 20B MIDTERM #2 REVIEW

Topic Outline for Integrated Algebra 2 and Trigonometry-R One Year Program with Regents in June

Topic Outline for Algebra 2 & and Trigonometry One Year Program

1. Find the domain of the following functions. Write your answer using interval notation. (9 pts.)

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

Math-2A. Lesson 10-3: Area of: -Triangles -rectangles -circles -trapezoids and Surface Area of: -Rectangular Prisms

Introduction to Cryptology. Lecture 19

5.1 Practice A. Name Date ( ) 23 15, , x = 20. ( ) 2

Critical Areas in 2011 Mathematics Frameworks

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Secondary Honors Algebra II Objectives

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

1.10 Continuity Brian E. Veitch

Section 5.3 Divide and Conquer Relations. 0,a m. - Division into thirds gives m = 3. Apply the telescoping technique described in Section 5.2.

Lecture 4: Stacks and Queues

PYP Mathematics Continuum

AP Calculus AB Summer Assignment

CS 188: Artificial Intelligence Spring Announcements

LESSON 8.1 RATIONAL EXPRESSIONS I

MATH 60 Course Notebook Chapter #1

Cross Curricular Connections. Activities and Differentiation. Assessment/ Benchmark. Grade Level Standard Domain Standard. Resources.

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

Functions and their Graphs

Section 20: Arrow Diagrams on the Integers

Math 121 (Lesieutre); 9.1: Polar coordinates; November 22, 2017

NOTES. [Type the document subtitle] Math 0310

Instructional Units Plan Algebra II

CSE 331 Winter 2018 Reasoning About Code I

Spring Lake Middle School- Math 7 Curriculum Map Updated: January 2018

Chapter 1 Review of Equations and Inequalities

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016

AN ALGEBRA PRIMER WITH A VIEW TOWARD CURVES OVER FINITE FIELDS

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER /2018

Sequences. 1. Number sequences. 2. Arithmetic sequences. Consider the illustrated pattern of circles:

Experiment #7 Centripetal Force Pre-lab Questions Hints

SUMMER MATH PACKET students. Entering Geometry-2B

CSE 331 Software Design & Implementation

SAT, Coloring, Hamiltonian Cycle, TSP

Radical Equations and Inequalities

. Then 2 3 the circumference is 8π 25 in. 2(1) both of which violate the original assumptions. Therefore, we have no solution.

1 Chapter 2 Perform arithmetic operations with polynomial expressions containing rational coefficients 2-2, 2-3, 2-4

Math 187, Spring 2018: Test III

What is proof? Lesson 1

3.4. ZEROS OF POLYNOMIAL FUNCTIONS

More on Regular Languages and Non-Regular Languages

The Research- Driven Solution to Raise the Quality of High School Core Courses. Algebra I I. Instructional Units Plan

Chapter P. Prerequisites. Slide P- 1. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Holt McDougal Larson Algebra Common Core Edition correlated to the South Carolina High School Core-Area Standards Intermediate Algebra

Class Notes: Solving Simultaneous Linear Equations by Gaussian Elimination. Consider a set of simultaneous linear equations:

COMP424 Computer Security

TAYLOR POLYNOMIALS DARYL DEFORD

NFC ACADEMY COURSE OVERVIEW

1 Limits and continuity

Algebra 2 Curriculum Map

NYS Algebra II and Trigonometry Suggested Sequence of Units (P.I's within each unit are NOT in any suggested order)

Lecture 21: Counting and Sampling Problems

Spiral Review Probability, Enter Your Grade Online Quiz - Probability Pascal's Triangle, Enter Your Grade

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and

Tennessee Comprehensive Assessment Program

Searching Algorithms. CSE21 Winter 2017, Day 3 (B00), Day 2 (A00) January 13, 2017

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

CS 70 Discrete Mathematics and Probability Theory Summer 2016 Dinh, Psomas, and Ye Discussion 8A Sol

b) since the remainder is 0 I need to factor the numerator. Synthetic division tells me this is true

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Algebra 2A Unit 1 Week 1 Day Activity Unit 1 Week 2 Day Activity Unit 1 Week 3 Day Activity Unit 2 Week 1 Day Activity

Lecture 5: Sep. 23 &25

Section 3.6 Complex Zeros

Introduction: Pythagorean Triplets

NFC ACADEMY COURSE OVERVIEW

Around the corner. Mathematics B-day 2015, Friday November 13, 9:00h-16:00h

NOTES ON 2009 MEMORANDUM

CSE332: Data Abstrac0ons Sec%on 2. HyeIn Kim Winter 2013

Curriculum Guide Algebra 2 Advanced

Correlation: California State Curriculum Standards of Mathematics for Grade 6 SUCCESS IN MATH: BASIC ALGEBRA

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

Day 2 and 3 Graphing Linear Inequalities in Two Variables.notebook. Formative Quiz. 1) Sketch the graph of the following linear equation.

Lesson #9 Simplifying Rational Expressions

Prentice Hall Mathematics, Algebra Correlated to: Achieve American Diploma Project Algebra II End-of-Course Exam Content Standards

Data Structures and Algorithms Winter Semester

Announcements Oct 17, 2013

Functions. 1. Any set of ordered pairs is a relation. Graph each set of ordered pairs. A. B. C.

GCSE Mathematics Non Calculator Higher Tier Free Practice Set 6 1 hour 45 minutes ANSWERS. Marks shown in brackets for each question (2) A* A B C D E

A Simple Implementation Technique for Priority Search Queues

Transcription:

Warmup A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen. The programmer returns with 12 loaves of bread.

Section 3: HW4, ADTs, and more Slides by Alex Mariakakis with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue

Announcements o HW3: due tonight o HW4: due next Thursday Agenda Polynomial arithmetic Abstract data types (ADT) Representation invariants (RI)

HW4: Polynomial Graphing Calculator Problem 0: Write pseudocode algorithms for polynomial operations Problem 1: Answer questions about RatNum Problem 2: Implement RatTerm Problem 3: Implement RatPoly Problem 4: Implement RatPolyStack Problem 5: Try out the calculator

Polynomial Addition (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5)

Polynomial Addition (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) + 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5

Polynomial Addition (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) + 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5

Polynomial Addition (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) + 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5 3x 5 + 5x 4-2x 3 - x 2 + x + 0

Polynomial Subtraction (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) - 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5

Polynomial Subtraction (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) - 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5

Polynomial Subtraction (5x 4 + 4x 3 - x 2 + 5) + (3x 5-2x 3 + x 5) - 5x 4 + 4x 3 - x 2 0x + 5 3x 5 0x 4-2x 3 0x 2 + x 5-3x 5 + 5x 4 + 6x 3 - x 2 - x + 10

Polynomial Multiplication (4x 3 - x 2 + 5) * (x 5)

Polynomial Multiplication (4x 3 - x 2 + 5) * (x 5) 4x 3 - x 2 + 5 * x 5

Polynomial Multiplication (4x 3 - x 2 + 5) * (x 5) 4x 3 - x 2 + 5 * x 5-20x 3 + 5x 2 25

Polynomial Multiplication (4x 3 - x 2 + 5) * (x 5) 4x 3 - x 2 + 5 * x 5-20x 3 + 5x 2 25 4x 4 - x 3 + 5x

Polynomial Multiplication (4x 3 - x 2 + 5) * (x 5) 4x 3 - x 2 + 5 * + x 5-20x 3 + 5x 2 25 4x 4 - x 3 + 5x 4x 4-21x 3 + 5x 2 + 5x - 25

Polynomial Division (5x 6 + 4x 4 x 3 + 5) / (x 3-2x 5)

Polynomial Division (5x 6 + 4x 4 x 3 + 5) / (x 3-2x 5) x 3-2x 5 5x 6 + 4x 4 x 3 + 5

Polynomial Division 1 0-2 - 5 5 0 4-1 0 0 5

Polynomial Division 5 1 0-2 - 5 5 0 4-1 0 0 5

Polynomial Division 5 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25

Polynomial Division 5 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24

Polynomial Division 5 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0

Polynomial Division 5 0 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0

Polynomial Division 5 0 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0

Polynomial Division 5 0 14 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0

Polynomial Division 5 0 14 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0 14 0-28 - 70

Polynomial Division 5 0 14 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0 14 0-28 - 70 0 24 28 70

Polynomial Division 5 0 14 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0 14 0-28 - 70 0 24 28 70 24 28 70 5

Polynomial Division 5 0 14 24 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0 14 0-28 - 70 0 24 28 70 24 28 70 5 24 0-48 120

Polynomial Division 5 0 14 24 1 0-2 - 5 5 0 4-1 0 0 5 5 0-10 - 25 0 0 14 24 14 24 0 14 24 0 0 14 0-28 - 70 0 24 28 70 24 28 70 5 24 0-48 120 0 28 118 125

Polynomial Division (5x 6 + 4x 4 x 3 + 5) / (x 3-2x 5) 5x 3 + 14x + 24

Polynomial Division (5x 6 + 4x 4 x 3 + 5) / (x 3-2x 5) 5x 3 + 14x + 24 + 28x 2 + 118x + 125 x 3-2x 5

RatThings RatNum o ADT for a Rational Number o Has NaN RatTerm o Single polynomial term o Coefficient (RatNum) & degree RatPoly o Sum of RatTerms RatPolyStack o Ordered collection of RatPolys

Stacks S[3] S[2] S[1] S[0]

Stacks S[3] S[2] S[1] push S[0]

Stacks S[3] S[2] push S[1] S[0]

Stacks S[3] push S[2] S[1] S[0]

Last In, First Out (LIFO) Stacks S[3] pop S[2] S[1] S[0]

CalculatorFrame Demo

ADT Example: Circle Circle on the Cartesian coordinate plane.

Abstraction Function Abstraction function: a mapping from internal state to abstract value Abstract fields may not map directly to representation fields o Circle has radius but not necessarily private int radius; Internal representation can be anything as long as it somehow encodes the abstract value

Representation Invariants Constrains an object s internal state Defines what must be true for abstraction function to hold If representation invariant is violated, the object is broken doesn t map to any abstract value

Circle: Class Specification What are the abstract fields (what the client sees)? Center Radius What are some derived fields? Circumference Area How can we implement this? #1: Center, radius #2: Center, edge #3: Corner of diameter

Circle Implementation 1 public class Circle1 { private Point center; private double rad; // Abstraction function: // AF(this) = a circle c such that // c.center = // c.radius = // Rep invariant: // } //...

Circle Implementation 1 public class Circle1 { private Point center; private double rad; // Abstraction function: // AF(this) = a circle c such that // c.center = this.center // c.radius = this.rad // Rep invariant: // center!= null && rad > 0 } //...

Circle Implementation 2 public class Circle2 { private Point center; private Point edge; // Abstraction function: // AF(this) = a circle c such that // c.center = // c.radius = // Rep invariant: // } //...

Circle Implementation 2 public class Circle2 { private Point center; private Point edge; // Abstraction function: // AF(this) = a circle c such that // c.center = this.center // c.radius = sqrt((center.x- edge.x)^2 + (center.y- edge.y)^2) (edge) } // Rep invariant: // center!= null && edge! null &&!center.equals //...

Circle Implementation 3 public class Circle3 { private Point corner1, corner2; // Abstraction function: // AF(this) = a circle c such that // c.center = // c.radius = // Rep invariant: // } //...

Circle Implementation 3 public class Circle3 { private Point corner1, corner2; // Abstraction function: // AF(this) = a circle c such that // c.center = <(corner1.x + corner2.x) / 2, (corner.y + corner2.y) / 2> // c.radius = (1/2)*sqrt((corner1.x- corner2.x)^2 + (corner1.y- corner2.y)^2) // Rep invariant: // corner1!= null && corner2!= null &&! corner1.equals(corner2) } //...

Checking RIs Representation invariant should hold before and after every public method Write and use checkrep() o Call before and after public methods o OK that it adds extra code Asserts won t be included on release builds Important for finding bugs

checkrep() Example public class Circle1 { private Point center; private double rad; private void checkrep() throws RuntimeException { if (center == null) { throw new RuntimeException( This does not have a center"); } } } if (radius <= 0) { throw new RuntimeException( This triangle has a negative radius ); }

ADT Example: NonNullStringList public class NonNullStringList { // Abstraction function: //?? // Rep invariant: //?? } public void add(string s) {... } public boolean remove(string s) {... } public String get(int i) {... }

NonNullStringList Implementation 1 public class NonNullStringList { // Abstraction function: // Index i in arr contains the ith element in the list // Rep invariant: // RI = [0,count- 1]!= null private String[] arr; private int count; } public void add(string s) {... } public boolean remove(string s) {... } public String get(int i) {... } Problems?

NonNullStringList Implementation 2 public class NonNullStringList { // Abstraction function: // Value in the nth node after head contains the nth item in the list // Rep invariant: // RI = Head has size nodes after it, each whose value is non- null, no cycle in ListNodes public int size; public ListNode head; } public void add(string s) {... } public boolean remove(string s) {... } public String get(int i) {... }