Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Similar documents
1. Answer: x or x. Explanation Set up the two equations, then solve each equation. x. Check

Rational numbers as decimals and as integer fractions

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.

Module 7 Highlights. Mastered Reviewed. Sections ,

Today is the last day to register for CU Succeed account AND claim your account. Tuesday is the last day to register for my class

Algebra 2 Common Core Summer Skills Packet

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

The Further Mathematics Support Programme

College Prep Algebra II Summer Packet

Notes for Unit 1 Part A: Rational vs. Irrational

School Year:


Math 083 Final Exam Practice

1.1 - Functions, Domain, and Range

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

Section A Arithmetic ( 5) Exercise A

You should be able to plot points on the coordinate axis. You should know that the the midpoint of the line segment joining (x, y 1 1

Polynomial and Rational Functions

Math Introduction to Advanced Mathematics

Integers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not.

Florida Math 0018 Correlation of the ALEKS course Florida Math 0018 to the Florida Mathematics Competencies - Lower

Example 1: Given below is the graph of the quadratic function f. Use the function and its graph to find the following: Outputs

Section 1.5. Finding Linear Equations

Lesson 1: Arithmetic Review

2.Simplification & Approximation

Iron County Schools. Yes! Less than 90 No! 90 No! More than 90. angle: an angle is made where two straight lines cross or meet each other at a point.

Math Content

CS 64 Week 1 Lecture 1. Kyle Dewey

MEI Desmos Tasks for AS Pure

WYSE Academic Challenge Computer Science Test (State) 2012 Solution Set

Mini-Lesson 1. Section 1.1: Order of Operations PEMDAS

Polynomial Functions Graphing Investigation Unit 3 Part B Day 1. Graph 1: y = (x 1) Graph 2: y = (x 1)(x + 2) Graph 3: y =(x 1)(x + 2)(x 3)

More About Factoring Trinomials

5.5 Completing the Square for the Vertex

SUMMER REVIEW PACKET 2 FOR STUDENTS ENTERING ALGEBRA 1

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

COP 4516: Math for Programming Contest Notes

Unit 2: Accentuate the Negative Name:

CS 202: Introduction to Computation Fall 2010: Exam #1

Class Book. Anita Straker, Tony Fisher, Rosalyn Hyde, Sue Jennings and Jonathan Longstaffe

Unit 6 Quadratic Functions

CS & IT Conversions. Magnitude 10,000 1,

Number Theory Open, Round 1 Test #101

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Number System. Introduction. Decimal Numbers

The domain of any rational function is all real numbers except the numbers that make the denominator zero or where q ( x)

A.4 Rationalizing the Denominator

NO CALCULATOR ON ANYTHING EXCEPT WHERE NOTED

( ) ( ) Completing the Square. Alg 3 1 Rational Roots Solving Polynomial Equations. A Perfect Square Trinomials

HOW TO DIVIDE: MCC6.NS.2 Fluently divide multi-digit numbers using the standard algorithm. WORD DEFINITION IN YOUR WORDS EXAMPLE

Chapter 0: Algebra II Review

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

r the COR d e s 3 A lg e b r a Alabama Pathways

r the COR d e s 3 A lg e b r a New York Common Core Pathways

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Algebra 1. Standard 11 Operations of Expressions. Categories Combining Expressions Multiply Expressions Multiple Operations Function Knowledge

Fractions. There are several terms that are commonly used when working with fractions.

Chapter 4 Section 2 Operations on Decimals

Problem. Prove that the square of any whole number n is a multiple of 4 or one more than a multiple of 4.

3.1 INTRODUCTION TO THE FAMILY OF QUADRATIC FUNCTIONS

RATIONAL FUNCTIONS Introductory Material from Earl Please read this!

ENE 334 Microprocessors

1. Divide by using long division. (8x 3 + 6x 2 + 7) (x + 2)

in this web service Cambridge University Press

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Math Glossary Numbers and Arithmetic

Unit 1 and Unit 2 Concept Overview

Course Number 432/433 Title Algebra II (A & B) H Grade # of Days 120

Assertions & Verification & Example Loop Invariants Example Exam Questions

Math 10- Chapter 2 Review

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Rev Name Date. . Round-off error is the answer to the question How wrong is the rounded answer?

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Course of study- Algebra Introduction: Algebra 1-2 is a course offered in the Mathematics Department. The course will be primarily taken by

Accuplacer Arithmetic Study Guide

6.1 Evaluate Roots and Rational Exponents

GRAPHING POLYNOMIALS DAY 2 U N I T 1 1

1. How many white tiles will be in Design 5 of the pattern? Explain your reasoning.

EXERCISE SET 10.2 MATD 0390 DUE DATE: INSTRUCTOR

Math 1125 Daily Calendar Spring 2016

Algebra II: Strand 3. Quadratic Functions; Topic 2. Digging Deeper; Task 3.2.1

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

Simplifying Square Root Expressions[In Class Version][Algebra 1 Honors].notebook August 26, Homework Assignment. Example 5 Example 6.

World Inside a Computer is Binary

UNIT 3 EXPRESSIONS AND EQUATIONS Lesson 3: Creating Quadratic Equations in Two or More Variables

9 Multiplication and Division

Algebraically Speaking Chalkdust Algebra 1 Fall Semester

Example 2: Simplify each of the following. Round your answer to the nearest hundredth. a

Introduction to Programming in C Department of Computer Science and Engineering\ Lecture No. #02 Introduction: GCD

Euclid's Algorithm. MA/CSSE 473 Day 06. Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm

3.5D Graphing Rational Functions

UCT Algorithm Circle: Number Theory

Student Success Center Arithmetic Study Guide for the ACCUPLACER (CPT)

Quadratic Functions. *These are all examples of polynomial functions.

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Number Systems. Both numbers are positive

Chapter (1) Eng. Mai Z. Alyazji

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Number Systems CHAPTER Positional Number Systems

Linear Equations in Two Variables

Transcription:

Chapter 1 An Introduction to Computer Science INVITATION TO Computer Science 1

Q8. Under what conditions would the well-known quadratic formula not be effectively computable? (Assume that you are working with real numbers.) a quadratic equation is a univariate polynomial equation of the second degree. Invitation to Computer Science, 6th Edition 2

Answer It is not effectively computable if b 2 4ac < 0 (since we cannot take the square root of a negative number) or if a = 0 (since we cannot divide by 0). Invitation to Computer Science, 6th Edition 3

Q10. The following is Euclid s 2,300-year-old algorithm for finding the greatest common divisor of two positive integers I and J. Step 1 Operation Get two positive integers as input; call the larger value I and the smaller value J 2 Divide I by J, and call the remainder R 3 If R is not 0, then reset I to the value of J, reset J to the value of R, and go back to Step 2 4 Print out the answer, which is the value of J 5 Stop Invitation to Computer Science, 6th Edition 4

1. Go through this algorithm using the input values 20 and 32. After each step of the algorithm is completed, give the values of I, J, and R. Determine the final output of the algorithm. 2. Does the algorithm work correctly when the two inputs are 0 and 32? Describe exactly what happens, and modify the algorithm so that it gives an appropriate error message. Step 1 Operation Get two positive integers as input; call the larger value I and the smaller value J 2 Divide I by J, and call the remainder R 3 If R is not 0, then reset I to the value of J, reset J to the value of R, and go back to Step 2 4 Print out the answer, which is the value of J 5 Stop Invitation to Computer Science, 6th Edition 5

Answer (a) Trace: Step 1: I = 32, J = 20, and R =?? Step 2: I = 32, J = 20, and R = 12 Step 3: I = 20, J = 12, and R = 12 Step 2: I = 20, J = 12, and R = 8 Step 3: I = 12, J = 8, and R = 8 Step 2: I = 12, J = 8, and R = 4 Step 3: I = 8, J = 4, and R = 4 Step 2: I = 8, J = 4, and R = 0 Step 4: Print J = 4 Invitation to Computer Science, 6th Edition 6

Answer (b) At Step 2 we are asked to divide I = 32 by J = 0, which cannot be done. We can fix the problem by adding a step between Step 1 and Step 2 that says: If J = 0, then print ERROR: division by 0 and Stop. Invitation to Computer Science, 6th Edition 7

Q 13. A student was asked to develop an algorithm to find and output the largest of three numerical values x, y, and z that are provided as input. Here is what was produced: Invitation to Computer Science, 6th Edition 8

Answer The algorithm will work correctly only if all three numbers are unique. If two or more numbers are identical, none of the Boolean expressions will be true and nothing will be output. To make this a correct solution you either have to specify in the problem statement that the three numbers provided must all be distinct or (better) change all of the comparison operations to in place of >. Invitation to Computer Science, 6th Edition 9

Quiz Q12 One way to do multiplication is by repeated addition. For example, 47 25 can be evaluated as 47 + 47 + 47 + + 47 (25 times). Sketch out an algorithm for multiplying two positive numbers a and b using this technique. Invitation to Computer Science, 6th Edition 10

Invitation to Computer Science, 6th Edition 11

Answer 12 A Multiplication Algorithm. Given: Two positive numbers a and b Wanted: A number c which contains the result of multiplying a and b Step 1: Set the value of c equal to 0 Step 2: Set the value of i equal to b Step 3: Repeat steps 4 and 5 until the value of i is 0 Step 4: Set the value of c to be c + a Step 5: Subtract 1 from i Step 6: Print out the final answer c Step 7: Stop This algorithm assumes that we know how to add two multiple-digit numbers together. We may assume this because we have the algorithm from the book which does exactly that. Invitation to Computer Science, 6th Edition 12

Challenge Question #1 Assume we have a computing agent that knows how to do onedigit subtraction where the first digit is at least as large as the second (i.e., we do not end up with a negative number). Thus, our computing agent can do such operations as 7 3 = 4, 9 1 = 8, and 5 5 = 0. It can also subtract a one-digit value from a two-digit value in the range 10 18 as long as the final result has only a single digit. This capability enables it to do such operations as 13 7 = 6, 10 2 = 8, and 18 9 = 9. Using these primitive capabilities, design an algorithm to do decimal subtraction on two m-digit numbers, where m 1. You will be given two unsigned whole numbers a mm1 a mm2 a 0 and b mm1 b mm2 b 0. Your algorithm must compute the value c mm1 c mm2 c 0, the difference of these two values. Invitation to Computer Science, 6th Edition 13

You may assume that the top number (a m1 a mm2 a 0 ) is greater than or equal to the bottom number (b mm1 b mm2 b 0 ) so that the result is not a negative value. However, do not assume that each individual digit a i is greater than or equal to b i. If the digit on the bottom is larger than the digit on the top, then you must implement a borrowing scheme to allow the subtraction to continue. (Caution: It may have been easy to learn subtraction as a first grader, but it is devilishly difficult to tell a computer how to do it!) Invitation to Computer Science, 6th Edition 14

Hint: We may perform subtraction, like addition, by subtracting one column at a time, starting with the rightmost column and working to the left. Since we know that the first number is larger than the second one, we know that we can always borrow from columns to the left of the current one. Therefore, if the upper number in the column (a i ) is smaller than the lower, we automatically borrow from the previous column. We can do this by subtracting one from the a i+1 value of the column to the left. If the a i+1 value were already zero, then it would become - 1. This automatically causes a borrow to occur on the next step. Invitation to Computer Science, 6th Edition 15