Python Programming: An Introduction to Computer Science

Size: px
Start display at page:

Download "Python Programming: An Introduction to Computer Science"

Transcription

1 Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1

2 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to defie ew fuctios i Pytho. To uderstad the details of fuctio calls ad parameter passig i Pytho. Pytho Programmig, 2/e 2

3 Objectives (cot.) To write programs that use fuctios to reduce code duplicatio ad icrease program modularity. Pytho Programmig, 2/e 3

4 The Fuctio of Fuctios So far, we ve see four differet types of fuctios: Our programs comprise a sigle fuctio called mai(). Built-i Pytho fuctios (abs) Fuctios from the stadard libraries (math.sqrt) Fuctios from the graphics module (p.getx()) Pytho Programmig, 2/e 4

5 The Fuctio of Fuctios Havig similar or idetical code i more tha oe place has some drawbacks. Issue oe: writig the same code twice or more. Issue two: This same code must be maitaied i two separate places. Fuctios ca be used to reduce code duplicatio ad make programs more easily uderstood ad maitaied. Pytho Programmig, 2/e 5

6 Fuctios, Iformally A fuctio is like a subprogram, a small program iside of a program. The basic idea we write a sequece of statemets ad the give that sequece a ame. We ca the execute this sequece at ay time by referrig to the ame. Pytho Programmig, 2/e 6

7 Fuctios, Iformally The part of the program that creates a fuctio is called a fuctio defiitio. Whe the fuctio is used i a program, we say the defiitio is called or ivoked. Pytho Programmig, 2/e 7

8 Fuctios, Iformally Happy Birthday lyrics def mai(): prit("happy birthday to you!" ) prit("happy birthday to you!" ) prit("happy birthday, dear Fred...") prit("happy birthday to you!") Gives us this >>> mai() Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred... Happy birthday to you! Pytho Programmig, 2/e 8

9 Fuctios, Iformally There s some duplicated code i the program! (prit("happy birthday to you!")) We ca defie a fuctio to prit out this lie: def happy(): prit("happy birthday to you!") With this fuctio, we ca rewrite our program. Pytho Programmig, 2/e 9

10 Fuctios, Iformally The ew program def sigfred(): happy() happy() prit("happy birthday, dear Fred...") happy() Gives us this output >>> sigfred() Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred... Happy birthday to you! Pytho Programmig, 2/e 10

11 Fuctios, Iformally Creatig this fuctio saved us a lot of typig! What if it s Lucy s birthday? We could write a ew siglucy fuctio! def siglucy(): happy() happy() prit("happy birthday, dear Lucy...") happy() Pytho Programmig, 2/e 11

12 Fuctios, Iformally We could write a mai program to sig to both Lucy ad Fred def mai(): sigfred() prit() siglucy() This gives us this ew output >>> mai() Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred.. Happy birthday to you! Happy birthday to you! Happy birthday to you! Happy birthday, dear Lucy... Happy birthday to you! Pytho Programmig, 2/e 12

13 Fuctios, Iformally This is workig great! But there s still a lot of code duplicatio. The oly differece betwee sigfred ad siglucy is the ame i the third prit statemet. These two routies could be collapsed together by usig a parameter. Pytho Programmig, 2/e 13

14 Fuctios, Iformally The geeric fuctio sig def sig(perso): happy() happy() prit("happy birthday, dear", perso + ". ) happy() This fuctio uses a parameter amed perso. A paramater is a variable that is iitialized whe the fuctio is called. Pytho Programmig, 2/e 14

15 Fuctios, Iformally Our ew output >>> sig("fred") Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred. Happy birthday to you! We ca put together a ew mai program! Pytho Programmig, 2/e 15

16 Fuctios, Iformally Our ew mai program: def mai(): sig("fred") prit() sig("lucy") Gives us this output: >>> mai() Happy birthday to you! Happy birthday to you! Happy birthday, dear Fred. Happy birthday to you! Happy birthday to you! Happy birthday to you! Happy birthday, dear Lucy. Happy birthday to you! Pytho Programmig, 2/e 16

17 Future Value with a Fuctio I the future value graphig program, we see similar code twice: # Draw bar for iitial pricipal bar = Rectagle(Poit(0, 0), Poit(1, pricipal)) bar.setfill("gree") bar.setwidth(2) bar.draw(wi) bar = Rectagle(Poit(year, 0), Poit(year+1, pricipal)) bar.setfill("gree") bar.setwidth(2) bar.draw(wi) Pytho Programmig, 2/e 17

18 Future Value with a Fuctio To properly draw the bars, we eed three pieces of iformatio. The year the bar is for How tall the bar should be The widow the bar will be draw i These three values ca be supplied as parameters to the fuctio. Pytho Programmig, 2/e 18

19 Future Value with a Fuctio The resultig fuctio looks like this: def drawbar(widow, year, height): # Draw a bar i widow startig at year with give height bar = Rectagle(Poit(year, 0), Poit(year+1, height)) bar.setfill("gree") bar.setwidth(2) bar.draw(widow) To use this fuctio, we supply the three values. If wi is a Graphwi, we ca draw a bar for year 0 ad pricipal of $2000 usig this call: drawbar(wi, 0, 2000) Pytho Programmig, 2/e 19

20 Fuctios ad Parameters: The Details It makes sese to iclude the year ad the pricipal i the drawbar fuctio, but why sed the widow variable? The scope of a variable refers to the places i a program a give variable ca be refereced. Pytho Programmig, 2/e 20

21 Fuctios ad Parameters: The Details Each fuctio is its ow little subprogram. The variables used iside of a fuctio are local to that fuctio, eve if they happe to have the same ame as variables that appear iside of aother fuctio. The oly way for a fuctio to see a variable from aother fuctio is for that variable to be passed as a parameter. Pytho Programmig, 2/e 21

22 Fuctios ad Parameters: The Details Sice the GraphWi i the variable wi is created iside of mai, it is ot directly accessible i drawbar. The widow parameter i drawbar gets assiged the value of wi from mai whe drawbar is called. Pytho Programmig, 2/e 22

23 Fuctios ad Parameters: The Details A fuctio defiitio looks like this: def <ame>(<formal-parameters>): <body> The ame of the fuctio must be a idetifier Formal-parameters is a possibly empty list of variable ames Pytho Programmig, 2/e 23

24 Fuctios ad Parameters: The Details Formal parameters, like all variables used i the fuctio, are oly accessible i the body of the fuctio. Variables with idetical ames elsewhere i the program are distict from the formal parameters ad variables iside of the fuctio body. Pytho Programmig, 2/e 24

25 Fuctios ad Parameters: The Details A fuctio is called by usig its ame followed by a list of actual parameters or argumets. <ame>(<actual-parameters>) Whe Pytho comes to a fuctio call, it iitiates a four-step process. Pytho Programmig, 2/e 25

26 Fuctios ad Parameters: The Details The callig program suspeds executio at the poit of the call. The formal parameters of the fuctio get assiged the values supplied by the actual parameters i the call. The body of the fuctio is executed. Cotrol returs to the poit just after where the fuctio was called. Pytho Programmig, 2/e 26

27 Fuctios ad Parameters: The Details Let s trace through the followig code: sig("fred") prit() sig("lucy") Whe Pytho gets to sig("fred"), executio of mai is temporarily suspeded. Pytho looks up the defiitio of sig ad sees that it has oe formal parameter, perso. Pytho Programmig, 2/e 27

28 Fuctios ad Parameters: The Detail The formal parameter is assiged the value of the actual parameter. It s as if the followig statemet had bee executed: perso = "Fred" Pytho Programmig, 2/e 28

29 Fuctios ad Parameters: The Details Note that the variable perso has just bee iitialized. Pytho Programmig, 2/e 29

30 Fuctios ad Parameters: The Details At this poit, Pytho begis executig the body of sig. The first statemet is aother fuctio call, to happy. What happes ext? Pytho suspeds the executio of sig ad trasfers cotrol to happy. happy cosists of a sigle prit, which is executed ad cotrol returs to where it left off i sig. Pytho Programmig, 2/e 30

31 Fuctios ad Parameters: The Details Executio cotiues i this way with two more trips to happy. Whe Pytho gets to the ed of sig, cotrol returs to mai ad cotiues immediately followig the fuctio call. Pytho Programmig, 2/e 31

32 Fuctios ad Parameters: The Details Notice that the perso variable i sig has disappeared! The memory occupied by local fuctio variables is reclaimed whe the fuctio exits. Local variables do ot retai ay values from oe fuctio executio to the ext. Pytho Programmig, 2/e 32

33 Fuctios ad Parameters: The Details The ext statemet is the bare prit, which produces a blak lie. Pytho ecouters aother call to sig, ad cotrol trasfers to the sig fuctio, with the formal parameter Lucy. Pytho Programmig, 2/e 33

34 Fuctios ad Parameters: The Details The body of sig is executed for Lucy with its three side trips to happy ad cotrol returs to mai. Pytho Programmig, 2/e 34

35 Fuctios ad Parameters: The Details Pytho Programmig, 2/e 35

36 Fuctios ad Paramters: The Details Oe thig ot addressed i this example was multiple parameters. I this case the formal ad actual parameters are matched up based o positio, e.g. the first actual parameter is assiged to the first formal parameter, the secod actual parameter is assiged to the secod formal parameter, etc. Pytho Programmig, 2/e 36

37 Fuctios ad Parameters: The Details As a example, cosider the call to drawbar: drawbar(wi, 0, pricipal) Whe cotrol is passed to drawbar, these parameters are matched up to the formal parameters i the fuctio headig: def drawbar(widow, year, height): Pytho Programmig, 2/e 37

38 Fuctios ad Parameters: The Details The et effect is as if the fuctio body had bee prefaced with three assigmet statemets: widow = wi year = 0 height = pricipal Pytho Programmig, 2/e 38

39 Gettig Results from a Fuctio Passig parameters provides a mechaism for iitializig the variables i a fuctio. Parameters act as iputs to a fuctio. We ca call a fuctio may times ad get differet results by chagig its parameters. Pytho Programmig, 2/e 39

40 Fuctios That Retur Values We ve already see umerous examples of fuctios that retur values to the caller. discrt = math.sqrt(b*b 4*a*c) The value b*b 4*a*c is the actual parameter of math.sqrt. We say sqrt returs the square root of its argumet. Pytho Programmig, 2/e 40

41 Fuctios That Retur Values This fuctio returs the square of a umber: def square(x): retur x*x Whe Pytho ecouters retur, it exits the fuctio ad returs cotrol to the poit where the fuctio was called. I additio, the value(s) provided i the retur statemet are set back to the caller as a expressio result. Pytho Programmig, 2/e 41

42 Fuctios That Retur Values >>> square(3) 9 >>> prit(square(4)) 16 >>> x = 5 >>> y = square(x) >>> prit(y) 25 >>> prit(square(x) + square(3)) 34 Pytho Programmig, 2/e 42

43 Fuctios That Retur Values We ca use the square fuctio to write a routie to calculate the distace betwee (x 1,y 1 ) ad (x 2,y 2 ). def distace(p1, p2): dist = math.sqrt(square(p2.getx() - p1.getx()) + square(p2.gety() - p1.gety())) retur dist Pytho Programmig, 2/e 43

44 Fuctios That Retur Values Sometimes a fuctio eeds to retur more tha oe value. To do this, simply list more tha oe expressio i the retur statemet. def sumdiff(x, y): sum = x + y diff = x y retur sum, diff Pytho Programmig, 2/e 44

45 Fuctios That Retur Values Whe callig this fuctio, use simultaeous assigmet. um1, um2 = eval(iput("eter two umbers (um1, um2) ")) s, d = sumdiff(um1, um2) prit("the sum is", s, "ad the differece is", d) As before, the values are assiged based o positio, so s gets the first value retured (the sum), ad d gets the secod (the differece). Pytho Programmig, 2/e 45

46 Fuctios That Retur Values Oe gotcha all Pytho fuctios retur a value, whether they cotai a retur statemet or ot. Fuctios without a retur had back a special object, deoted Noe. A commo problem is writig a valuereturig fuctio ad omittig the retur! Pytho Programmig, 2/e 46

47 Fuctios That Retur Values If your value-returig fuctios produce strage messages, check to make sure you remembered to iclude the retur! Pytho Programmig, 2/e 47

48 Fuctios that Modify Parameters Retur values are the mai way to sed iformatio from a fuctio back to the caller. Sometimes, we ca commuicate back to the caller by makig chages to the fuctio parameters. Uderstadig whe ad how this is possible requires the mastery of some subtle details about how assigmet works ad the relatioship betwee actual ad formal parameters. Pytho Programmig, 2/e 48

49 Fuctios that Modify Parameters Suppose you are writig a program that maages bak accouts. Oe fuctio we would eed to do is to accumulate iterest o the accout. Let s look at a first-cut at the fuctio. def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace Pytho Programmig, 2/e 49

50 Fuctios that Modify Parameters The itet is to set the balace of the accout to a ew value that icludes the iterest amout. Let s write a mai program to test this: def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 50

51 Fuctios that Modify Parameters We hope that that the 5% will be added to the amout, returig >>> test() 1000 What wet wrog? Nothig! Pytho Programmig, 2/e 51

52 Fuctios that Modify Parameters The first two lies of the test fuctio create two local variables called amout ad rate which are give the iitial values of 1000 ad 0.05, respectively. def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 52

53 Fuctios that Modify Parameters Cotrol the trasfers to the additerest fuctio. The formal parameters balace ad rate are assiged the values of the actual parameters amout ad rate. Eve though rate appears i both, they are separate variables (because of scope rules). def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 53

54 Fuctios that Modify Parameters The assigmet of the parameters causes the variables balace ad rate i additerest to refer to the values of the actual parameters! def additerest(balace, rate): ewbalace = balace*(1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 54

55 Fuctios that Modify Parameters Pytho Programmig, 2/e 55

56 Fuctios that Modify Parameters Executig the first lie of additerest creates a ew variable, ewbalace. balace is the assiged the value of ewbalace. def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 56

57 Fuctios that Modify Parameters balace ow refers to the same value as ewbalace, but this had o effect o amout i the test fuctio. def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit (amout) Pytho Programmig, 2/e 57

58 Fuctios that Modify Parameters Pytho Programmig, 2/e 58

59 Fuctios that Modify Parameters Executio of additerest has completed ad cotrol returs to test. The local variables, icludig the parameters, i additerest go away, but amout ad rate i the test fuctio still refer to their iitial values! def additerest(balace, rate): ewbalace = balace * (1 + rate) balace = ewbalace def test(): amout = 1000 rate = 0.05 additerest(amout, rate) prit(amout) Pytho Programmig, 2/e 59

60 Fuctios that Modify Parameters To summarize: the formal parameters of a fuctio oly receive the values of the actual parameters. The fuctio does ot have access to the variable that holds the actual parameter. Pytho is said to pass all parameters by value. Pytho Programmig, 2/e 60

61 Fuctios that Modify Parameters Some programmig laguages (C++, Ada, ad may more) do allow variables themselves to be set as parameters to a fuctio. This mechaism is said to pass parameters by referece. Whe a ew value is assiged to the formal parameter, the value of the variable i the callig program actually chages. Pytho Programmig, 2/e 61

62 Fuctios that Modify Parameters Sice Pytho does t have this capability, oe alterative would be to chage the additerest fuctio so that it returs the ewbalace. Pytho Programmig, 2/e 62

63 Fuctios that Modify Parameters def additerest(balace, rate): ewbalace = balace * (1 + rate) retur ewbalace def test(): amout = 1000 rate = 0.05 amout = additerest(amout, rate) prit(amout) test() Pytho Programmig, 2/e 63

64 Fuctios that Modify Parameters Istead of lookig at a sigle accout, say we are writig a program for a bak that deals with may accouts. We could store the accout balaces i a list, the add the accrued iterest to each of the balaces i the list. We could update the first balace i the list with code like: balaces[0] = balaces[0] * (1 + rate) Pytho Programmig, 2/e 64

65 Fuctios that Modify Parameters This code says, multiply the value i the 0 th positio of the list by (1 + rate) ad store the result back ito the 0 th positio of the list. A more geeral way to do this would be with a loop that goes through positios 0, 1,, legth 1. Pytho Programmig, 2/e 65

66 Fuctios that Modify Parameters # additerest3.py # Illustrates modificatio of a mutable parameter (a list). def additerest(balaces, rate): for i i rage(le(balaces)): balaces[i] = balaces[i] * (1+rate) def test(): amouts = [1000, 2200, 800, 360] rate = 0.05 additerest(amouts, 0.05) prit(amouts) test() Pytho Programmig, 2/e 66

67 Fuctios that Modify Parameters Remember, our origial code had these values: [1000, 2200, 800, 360] The program returs: [1050.0, , 840.0, 378.0] What happeed? Pytho passes parameters by value, but it looks like amouts has bee chaged! Pytho Programmig, 2/e 67

68 Fuctios that Modify Parameters The first two lies of test create the variables amouts ad rate. The value of the variable amouts is a list object that cotais four it values. def additerest(balaces, rate): for i i rage(le(balaces)): balaces[i] = balaces[i] * (1+rate) def test(): amouts = [1000, 2200, 800, 360] rate = 0.05 additerest(amouts, 0.05) prit(amouts) Pytho Programmig, 2/e 68

69 Fuctios that Modify Parameters Pytho Programmig, 2/e 69

70 Fuctios that Modify Parameters Next, additerest executes. The loop goes through each idex i the rage 0, 1,, legth 1 ad updates that value i balaces. def additerest(balaces, rate): for i i rage(le(balaces)): balaces[i] = balaces[i] * (1+rate) def test(): amouts = [1000, 2200, 800, 360] rate = 0.05 additerest(amouts, 0.05) prit(amouts) Pytho Programmig, 2/e 70

71 Fuctios that Modify Parameters Pytho Programmig, 2/e 71

72 Fuctios that Modify Parameters I the diagram the old values are left hagig aroud to emphasize that the umbers i the boxes have ot chaged, but the ew values were created ad assiged ito the list. The old values will be destroyed durig garbage collectio. def additerest(balaces, rate): for i i rage(le(balaces)): balaces[i] = balaces[i] * (1+rate) def test(): amouts = [1000, 2200, 800, 360] rate = 0.05 additerest(amouts, 0.05) prit amouts Pytho Programmig, 2/e 72

73 Fuctios that Modify Parameters Whe additerest termiates, the list stored i amouts ow cotais the ew values. The variable amouts was t chaged (it s still a list), but the state of that list has chaged, ad this chage is visible to the callig program. Pytho Programmig, 2/e 73

74 Fuctios that Modify Parameters Parameters are always passed by value. However, if the value of the variable is a mutable object (like a list of graphics object), the chages to the state of the object will be visible to the callig program. This situatio is aother example of the aliasig issue discussed i Chapter 4! Pytho Programmig, 2/e 74

75 Fuctios ad Program Structure So far, fuctios have bee used as a mechaism for reducig code duplicatio. Aother reaso to use fuctios is to make your programs more modular. As the algorithms you desig get icreasigly complex, it gets more ad more difficult to make sese out of the programs. Pytho Programmig, 2/e 75

76 Fuctios ad Program Structure Oe way to deal with this complexity is to break a algorithm dow ito smaller subprograms, each of which makes sese o its ow. This topic will be discussed i more detail i Chapter 9. Pytho Programmig, 2/e 76

77 Fuctios ad Program Structure def mai(): # Itroductio prit("this program plots the growth of a 10 year ivestmet.") Text(Poit(-1, 5000), ' 5.0K').draw(wi) Text(Poit(-1, 7500), ' 7.5k').draw(wi) Text(Poit(-1, 10000), '10.0K').draw(wi) # Get pricipal ad iterest rate pricipal = eval(iput("eter the iitial pricipal: ")) apr = eval(iput("eter the aualized iterest rate: ")) # Create a graphics widow with labels o left edge wi = GraphWi("Ivestmet Growth Chart", 320, 240) wi.setbackgroud("white") wi.setcoords(-1.75,-200, 11.5, 10400) Text(Poit(-1, 0), ' 0.0K').draw(wi) Text(Poit(-1, 2500), ' 2.5K').draw(wi) # Draw bar for iitial pricipal drawbar(wi, 0, pricipal) # Draw a bar for each subsequet year for year i rage(1, 11): pricipal = pricipal * (1 + apr) drawbar(wi, year, pricipal) iput("press <Eter> to quit.") wi.close() Pytho Programmig, 2/e 77

78 Fuctios ad Program Structure We ca make this program more readable by movig the middle eight lies that create the widow where the chart will be draw ito a value returig fuctio. Pytho Programmig, 2/e 78

79 Fuctios ad Program Structure def createlabeledwidow(): widow = GraphWi("Ivestmet Growth Chart", 320, 240) widow.setbackgroud("white") widow.setcoords(-1.75,-200, 11.5, 10400) Text(Poit(-1, 0), ' 0.0K').draw(widow) Text(Poit(-1, 2500), ' 2.5K').draw(widow) Text(Poit(-1, 5000), ' 5.0K').draw(widow) Text(Poit(-1, 7500), ' 7.5k').draw(widow) Text(Poit(-1, 10000), '10.0K').draw(widow) retur widow def mai(): prit("this program plots the growth of a 10 year ivestmet.") pricipal = eval(iput("eter the iitial pricipal: ")) apr = eval(iput("eter the aualized iterest rate: ")) wi = createlabeledwidow() drawbar(wi, 0, pricipal) for year i rage(1, 11): pricipal = pricipal * (1 + apr) drawbar(wi, year, pricipal) iput("press <Eter> to quit.") wi.close() Pytho Programmig, 2/e 79

CHAPTER 6 DEFINING FUNCTIONS Python Programming: An Introduction to Computer Science

CHAPTER 6 DEFINING FUNCTIONS Python Programming: An Introduction to Computer Science CHAPTER 6 DEFINING FUNCTIONS Python Programming: An Introduction to Computer Science Objectives æ To understand why programmers divide programs up into sets of cooperating functions. æ To be able to define

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Chapter 6 Defining Functions Python Programming, 3/e 1 Objectives n To understand why programmers divide programs up into sets of cooperating functions.

More information

Lecture. Defining Functions. Richard E Sarkis CSC 161: The Art of Programming

Lecture. Defining Functions. Richard E Sarkis CSC 161: The Art of Programming Lecture Defining Functions Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To understand why programmers divide program code up into sets of cooperating functions To be able

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Chapter 6 Defining Functions Python Programming, 2/e 1 Objectives To understand why programmers divide programs up into sets of cooperating functions.

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 6 (Part 2) Instructor: Long Ma The Department of Computer Science Objectives--Defining Functions 2 To understand why programmers

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

6. Defining Functions

6. Defining Functions 6. Defining Functions Original Slides by John Zelle, 2010. (Minor modifications by the instructor) Intelligent Data Systems Lab. Seoul National University Objectives To understand why programmers divide

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions CS 111: Program Desig I Lecture # 7: First Loop, Web Crawler, Fuctios Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 18, 2018 What will this prit? x = 5 if x == 3: prit("hi!")

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 6 Part 1 The Department of Computer Science Objectives 2 To understand why programmers divide programs up into sets of cooperating

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

Lecture 9: Exam I Review

Lecture 9: Exam I Review CS 111 (Law): Program Desig I Lecture 9: Exam I Review Robert H. Sloa & Richard Warer Uiversity of Illiois, Chicago September 22, 2016 This Class Discuss midterm topics Go over practice examples Aswer

More information

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access CS 111: Program Desig I Lecture # 7: Web Crawler, Fuctios; Ope Access Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 13, 2016 Lab Hit/Remider word = "hi" word.upper() à "HI" Questio

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information

It just came to me that I 8.2 GRAPHS AND CONVERGENCE

It just came to me that I 8.2 GRAPHS AND CONVERGENCE 44 Chapter 8 Discrete Mathematics: Fuctios o the Set of Natural Numbers (a) Take several odd, positive itegers for a ad write out eough terms of the 3N sequece to reach a repeatig loop (b) Show that ot

More information

Investigation Monitoring Inventory

Investigation Monitoring Inventory Ivestigatio Moitorig Ivetory Name Period Date Art Smith has bee providig the prits of a egravig to FieArt Gallery. He plas to make just 2000 more prits. FieArt has already received 70 of Art s prits. The

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only

Bezier curves. Figure 2 shows cubic Bezier curves for various control points. In a Bezier curve, only Edited: Yeh-Liag Hsu (998--; recommeded: Yeh-Liag Hsu (--9; last updated: Yeh-Liag Hsu (9--7. Note: This is the course material for ME55 Geometric modelig ad computer graphics, Yua Ze Uiversity. art of

More information

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle: Recursio Recursio Jordi Cortadella Departmet of Computer Sciece Priciple: Reduce a complex problem ito a simpler istace of the same problem Recursio Itroductio to Programmig Dept. CS, UPC 2 Mathematical

More information

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright CS 111: Program Desig I Lecture 20: Web crawlig, HTML, Copyright Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago November 8, 2016 WEB CRAWLER AGAIN Two bits of useful Pytho sytax Do't eed

More information

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013 Code Review s Authors: Mika V. Mätylä ad Casper Lasseius Origial versio: 4 Sep, 2007 Made available olie: 24 April, 2013 This documet cotais further details of the code review defects preseted i [1]. of

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

Alpha Individual Solutions MAΘ National Convention 2013

Alpha Individual Solutions MAΘ National Convention 2013 Alpha Idividual Solutios MAΘ Natioal Covetio 0 Aswers:. D. A. C 4. D 5. C 6. B 7. A 8. C 9. D 0. B. B. A. D 4. C 5. A 6. C 7. B 8. A 9. A 0. C. E. B. D 4. C 5. A 6. D 7. B 8. C 9. D 0. B TB. 570 TB. 5

More information

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs CHAPTER IV: GRAPH THEORY Sectio : Itroductio to Graphs Sice this class is called Number-Theoretic ad Discrete Structures, it would be a crime to oly focus o umber theory regardless how woderful those topics

More information

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

More information

CSE 111 Bio: Program Design I Lecture 17: software development, list methods

CSE 111 Bio: Program Design I Lecture 17: software development, list methods CSE 111 Bio: Program Desig I Lecture 17: software developmet, list methods Robert H. Sloa(CS) & Rachel Poretsky(Bio) Uiversity of Illiois, Chicago October 19, 2017 NESTED LOOPS: REVIEW Geerate times table

More information

CSE 111 Bio: Program Design I Class 11: loops

CSE 111 Bio: Program Design I Class 11: loops SE 111 Bio: Program Desig I lass 11: loops Radall Muroe, xkcd.com/1411/ Robert H. Sloa (S) & Rachel Poretsky (Bio) Uiversity of Illiois, hicago October 2, 2016 Pytho ets Loopy! he Pytho, Busch ardes Florida

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists CS 111: Program Desig I Lecture 16: Module Review, Ecodigs, Lists Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 18, 2016 Last time Dot otatio ad methods Padas: user maual poit

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

CS 111: Program Design I Lecture 21: Network Analysis. Robert H. Sloan & Richard Warner University of Illinois at Chicago April 10, 2018

CS 111: Program Design I Lecture 21: Network Analysis. Robert H. Sloan & Richard Warner University of Illinois at Chicago April 10, 2018 CS 111: Program Desig I Lecture 21: Network Aalysis Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago April 10, 2018 NETWORK ANALYSIS Which displays a graph i the sese of graph/etwork aalysis?

More information

Data diverse software fault tolerance techniques

Data diverse software fault tolerance techniques Data diverse software fault tolerace techiques Complemets desig diversity by compesatig for desig diversity s s limitatios Ivolves obtaiig a related set of poits i the program data space, executig the

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

Appendix D. Controller Implementation

Appendix D. Controller Implementation COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Appedix D Cotroller Implemetatio Cotroller Implemetatios Combiatioal logic (sigle-cycle); Fiite state machie (multi-cycle, pipelied);

More information

IMP: Superposer Integrated Morphometrics Package Superposition Tool

IMP: Superposer Integrated Morphometrics Package Superposition Tool IMP: Superposer Itegrated Morphometrics Package Superpositio Tool Programmig by: David Lieber ( 03) Caisius College 200 Mai St. Buffalo, NY 4208 Cocept by: H. David Sheets, Dept. of Physics, Caisius College

More information

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016 CS 111: Program Desig I Lecture 15: Objects, Padas, Modules Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 13, 2016 OBJECTS AND DOT NOTATION Objects (Implicit i Chapter 2, Variables,

More information

Guide to Applying Online

Guide to Applying Online Guide to Applyig Olie Itroductio Respodig to requests for additioal iformatio Reportig: submittig your moitorig or ed of grat Pledges: submittig your Itroductio This guide is to help charities submit their

More information

Counting Regions in the Plane and More 1

Counting Regions in the Plane and More 1 Coutig Regios i the Plae ad More 1 by Zvezdelia Stakova Berkeley Math Circle Itermediate I Group September 016 1. Overarchig Problem Problem 1 Regios i a Circle. The vertices of a polygos are arraged o

More information

Overview Chapter 12 A display model

Overview Chapter 12 A display model Overview Chapter 12 A display model Why graphics? A graphics model Examples Bjare Stroustrup www.stroustrup.com/programmig 3 Why bother with graphics ad GUI? Why bother with graphics ad GUI? It s very

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS) CSC165H1, Witer 018 Learig Objectives By the ed of this worksheet, you will: Aalyse the ruig time of fuctios cotaiig ested loops. 1. Nested loop variatios. Each of the followig fuctios takes as iput a

More information

The Closest Line to a Data Set in the Plane. David Gurney Southeastern Louisiana University Hammond, Louisiana

The Closest Line to a Data Set in the Plane. David Gurney Southeastern Louisiana University Hammond, Louisiana The Closest Lie to a Data Set i the Plae David Gurey Southeaster Louisiaa Uiversity Hammod, Louisiaa ABSTRACT This paper looks at three differet measures of distace betwee a lie ad a data set i the plae:

More information

Lecture 28: Data Link Layer

Lecture 28: Data Link Layer Automatic Repeat Request (ARQ) 2. Go ack N ARQ Although the Stop ad Wait ARQ is very simple, you ca easily show that it has very the low efficiecy. The low efficiecy comes from the fact that the trasmittig

More information

FURTHER INTEGRATION TECHNIQUES (TRIG, LOG, EXP FUNCTIONS)

FURTHER INTEGRATION TECHNIQUES (TRIG, LOG, EXP FUNCTIONS) Mathematics Revisio Guides More Trigoometric ad Log Itegrals Page of 7 MK HOME TUITION Mathematics Revisio Guides Level: AS / A Level AQA : C Edexcel: C OCR: C OCR MEI: C FURTHER INTEGRATION TECHNIQUES

More information

One advantage that SONAR has over any other music-sequencing product I ve worked

One advantage that SONAR has over any other music-sequencing product I ve worked *gajedra* D:/Thomso_Learig_Projects/Garrigus_163132/z_productio/z_3B2_3D_files/Garrigus_163132_ch17.3d, 14/11/08/16:26:39, 16:26, page: 647 17 CAL 101 Oe advatage that SONAR has over ay other music-sequecig

More information

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts CS 111 Gree: Program Desig I Lecture 27: Speed (cot.); partig thoughts By Nascarkig - Ow work, CC BY-SA 4.0, https://commos.wikimedia.org/w/idex.php?curid=38671041 Robert H. Sloa (CS) & Rachel Poretsky

More information

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Cocurrecy Threads ad Cocurrecy i Java: Part 1 What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

Parabolic Path to a Best Best-Fit Line:

Parabolic Path to a Best Best-Fit Line: Studet Activity : Fidig the Least Squares Regressio Lie By Explorig the Relatioship betwee Slope ad Residuals Objective: How does oe determie a best best-fit lie for a set of data? Eyeballig it may be

More information

Project 2.5 Improved Euler Implementation

Project 2.5 Improved Euler Implementation Project 2.5 Improved Euler Implemetatio Figure 2.5.10 i the text lists TI-85 ad BASIC programs implemetig the improved Euler method to approximate the solutio of the iitial value problem dy dx = x+ y,

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Threads ad Cocurrecy i Java: Part 1 1 Cocurrecy What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

Numerical Methods Lecture 6 - Curve Fitting Techniques

Numerical Methods Lecture 6 - Curve Fitting Techniques Numerical Methods Lecture 6 - Curve Fittig Techiques Topics motivatio iterpolatio liear regressio higher order polyomial form expoetial form Curve fittig - motivatio For root fidig, we used a give fuctio

More information

Review: The ACID properties

Review: The ACID properties Recovery Review: The ACID properties A tomicity: All actios i the Xactio happe, or oe happe. C osistecy: If each Xactio is cosistet, ad the DB starts cosistet, it eds up cosistet. I solatio: Executio of

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

Software development of components for complex signal analysis on the example of adaptive recursive estimation methods.

Software development of components for complex signal analysis on the example of adaptive recursive estimation methods. Software developmet of compoets for complex sigal aalysis o the example of adaptive recursive estimatio methods. SIMON BOYMANN, RALPH MASCHOTTA, SILKE LEHMANN, DUNJA STEUER Istitute of Biomedical Egieerig

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

Evaluation scheme for Tracking in AMI

Evaluation scheme for Tracking in AMI A M I C o m m u i c a t i o A U G M E N T E D M U L T I - P A R T Y I N T E R A C T I O N http://www.amiproject.org/ Evaluatio scheme for Trackig i AMI S. Schreiber a D. Gatica-Perez b AMI WP4 Trackig:

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

1.2 Binomial Coefficients and Subsets

1.2 Binomial Coefficients and Subsets 1.2. BINOMIAL COEFFICIENTS AND SUBSETS 13 1.2 Biomial Coefficiets ad Subsets 1.2-1 The loop below is part of a program to determie the umber of triagles formed by poits i the plae. for i =1 to for j =

More information

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Single-Cycle Disadvantages & Advantages

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Single-Cycle Disadvantages & Advantages COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 4 The Processor Pipeliig Sigle-Cycle Disadvatages & Advatages Clk Uses the clock cycle iefficietly the clock cycle must

More information

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions U.C. Berkeley CS170 : Algorithms Midterm 1 Solutios Lecturers: Sajam Garg ad Prasad Raghavedra Feb 1, 017 Midterm 1 Solutios 1. (4 poits) For the directed graph below, fid all the strogly coected compoets

More information

Arithmetic Sequences

Arithmetic Sequences . Arithmetic Sequeces COMMON CORE Learig Stadards HSF-IF.A. HSF-BF.A.1a HSF-BF.A. HSF-LE.A. Essetial Questio How ca you use a arithmetic sequece to describe a patter? A arithmetic sequece is a ordered

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 20 Itroductio to Trasactio Processig Cocepts ad Theory Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Trasactio Describes local

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

The Magma Database file formats

The Magma Database file formats The Magma Database file formats Adrew Gaylard, Bret Pikey, ad Mart-Mari Breedt Johaesburg, South Africa 15th May 2006 1 Summary Magma is a ope-source object database created by Chris Muller, of Kasas City,

More information

Using the Keyboard. Using the Wireless Keyboard. > Using the Keyboard

Using the Keyboard. Using the Wireless Keyboard. > Using the Keyboard 1 A wireless keyboard is supplied with your computer. The wireless keyboard uses a stadard key arragemet with additioal keys that perform specific fuctios. Usig the Wireless Keyboard Two AA alkalie batteries

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

Getting Started. Getting Started - 1

Getting Started. Getting Started - 1 Gettig Started Gettig Started - 1 Issue 1 Overview of Gettig Started Overview of Gettig Started This sectio explais the basic operatios of the AUDIX system. It describes how to: Log i ad log out of the

More information

Weston Anniversary Fund

Weston Anniversary Fund Westo Olie Applicatio Guide 2018 1 This guide is desiged to help charities applyig to the Westo to use our olie applicatio form. The Westo is ope to applicatios from 5th Jauary 2018 ad closes o 30th Jue

More information

OCR Statistics 1. Working with data. Section 3: Measures of spread

OCR Statistics 1. Working with data. Section 3: Measures of spread Notes ad Eamples OCR Statistics 1 Workig with data Sectio 3: Measures of spread Just as there are several differet measures of cetral tedec (averages), there are a variet of statistical measures of spread.

More information

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

More information

Homework 1 Solutions MA 522 Fall 2017

Homework 1 Solutions MA 522 Fall 2017 Homework 1 Solutios MA 5 Fall 017 1. Cosider the searchig problem: Iput A sequece of umbers A = [a 1,..., a ] ad a value v. Output A idex i such that v = A[i] or the special value NIL if v does ot appear

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as a Itroductio to Objects ad Classes Overview 6.1 Streams ad Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams ad Basic File I/O I/O Streams I/O refers

More information

Chapter 3 Classification of FFT Processor Algorithms

Chapter 3 Classification of FFT Processor Algorithms Chapter Classificatio of FFT Processor Algorithms The computatioal complexity of the Discrete Fourier trasform (DFT) is very high. It requires () 2 complex multiplicatios ad () complex additios [5]. As

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

The number n of subintervals times the length h of subintervals gives length of interval (b-a). Simulator with MadMath Kit: Riema Sums (Teacher s pages) I your kit: 1. GeoGebra file: Ready-to-use projector sized simulator: RiemaSumMM.ggb 2. RiemaSumMM.pdf (this file) ad RiemaSumMMEd.pdf (educator's

More information

CS 111: Program Design I Lecture #26: Heat maps, Nothing, Predictive Policing

CS 111: Program Design I Lecture #26: Heat maps, Nothing, Predictive Policing CS 111: Program Desig I Lecture #26: Heat maps, Nothig, Predictive Policig Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago November 29, 2018 Some Logistics Extra credit: Sample Fial Exam

More information

Message Integrity and Hash Functions. TELE3119: Week4

Message Integrity and Hash Functions. TELE3119: Week4 Message Itegrity ad Hash Fuctios TELE3119: Week4 Outlie Message Itegrity Hash fuctios ad applicatios Hash Structure Popular Hash fuctios 4-2 Message Itegrity Goal: itegrity (ot secrecy) Allows commuicatig

More information

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998 Su Microsystems, Ic. 2550 Garcia Aveue Moutai View, CA 94045 415 960-1300 X3T10/95-229, Revisio 0 April 18, 1998 % Su Logo for Joh Lohmeyer Chairperso, X3T10 Symbios Logic Ic. 1635 Aeroplaza Drive Colorado

More information

The isoperimetric problem on the hypercube

The isoperimetric problem on the hypercube The isoperimetric problem o the hypercube Prepared by: Steve Butler November 2, 2005 1 The isoperimetric problem We will cosider the -dimesioal hypercube Q Recall that the hypercube Q is a graph whose

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

NTH, GEOMETRIC, AND TELESCOPING TEST

NTH, GEOMETRIC, AND TELESCOPING TEST NTH, GEOMETRIC, AND TELESCOPING TEST Sectio 9. Calculus BC AP/Dual, Revised 08 viet.dag@humbleisd.et /4/08 0:0 PM 9.: th, Geometric, ad Telescopig Test SUMMARY OF TESTS FOR SERIES Lookig at the first few

More information