Mathematics. Programming

Size: px
Start display at page:

Download "Mathematics. Programming"

Transcription

1 Mathematics for the Digital Age ad Programmig i Pytho >>> Secod Editio: with Pytho 3 Maria Litvi Phillips Academy, Adover, Massachusetts Gary Litvi Skylight Software, Ic. Skylight Publishig Adover, Massachusetts

2 Skylight Publishig 9 Bartlet Street, Suite 70 Adover, MA 080 web: sales@skylit.com support@skylit.com Copyright 200 by Maria Litvi, Gary Litvi, ad Skylight Publishig All rights reserved. No part of this publicatio may be reproduced, stored i a retrieval system, or trasmitted, i ay form or by ay meas, electroic, mechaical, photocopyig, recordig, or otherwise, without the prior writte permissio of the authors ad Skylight Publishig. Library of Cogress Cotrol Number: ISBN (soft cover) ISBN (hard cover) The ames of commercially available software ad products metioed i this book are used for idetificatio purposes oly ad may be trademarks or registered trademarks owed by corporatios ad other commercial etities. Skylight Publishig ad the authors have o affiliatio with ad disclaim ay sposorship or edorsemet by ay of these products maufacturers or trademarks owers Prited i the Uited States of America

3 Recurrece Relatios ad Recursio. Prologue I Chapter we talked about differet ways to defie a fuctio: i words, with a table, with a chart, or with a formula. But we left out oe very importat method: we ca also describe a fuctio, especially a fuctio o positive (or o-egative) itegers, recursively. Here is a example. Suppose you state that a fuctio f with the domai of all positive itegers is defied as follows:, if = f( ) = f( ), if > Copyright by Skylight Publishig This defiitio does ot tell us right away how to fid the value of f ( ). f ( ) is described i terms of f( ) (except for oe simple base case, = ). Ad yet, with some work, we ca fid the value of f ( ) for ay positive. Let s see: we kow that f () =. Next: f(2) = 2 f() = 2 = 2. Next: f(3) = 3 f(2) = 3 2= 6. Next: f(4) = 4 f(3) = 4 6= 24. Ad so o. There is oly oe fuctio that satisfies the above defiitio. I this case you ca easily fid a formula to describe this fuctio: it is our old fried f ( ) =! (-factorial). Recursio is a powerful tool for defiig fuctios. The desigers of computer hardware ad programmig laguages have made sure that recursio is also supported i programmig laguages..2 Recurrece Relatios Recall that a fuctio defied o the set of all positive itegers ca be expressed as a sequece of the fuctio s values: a, a 2,..., a,... To defie such a fuctio recursively, we defie each term of the sequece, except the first (or, perhaps, the first few), through its relatio to the previous term(s). The relatio that coects the 89

4 90 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION -th term to oe or more of the previous terms is ofte the same for each. It is called a recurrece relatio. For example: a = a = a, for ay 2 We get, agai, a =!. This is the same as our recursive defiitio of!, just rewritte i a slightly differet way. It is easy to calculate o a computer the values of a sequece defied through a recurrece relatio. Recall, for example, our calculatio of s( ) = i Chapter 4. We oticed that s (0) = 0 ad s ( ) = s ( ) +, for ay 2. This led to the followig Pytho code: = sum = 0 while <= Max: sum += prit('{0:3d} {:6d}'.format(, sum)) += Copyright by Skylight Publishig Here sum stads for ( ) calculatig successive values of s ( ). s. Iteratios through the while loop are equivalet to Oe of the famous sequeces defied with a recurrece relatio is called Fiboacci umbers: f = ; f2 = f = f + f 2,if > 2. This sequece is amed after Leoardo Fiboacci (the ame meas so of Boaccio) who lived i Pisa i the 3th cetury, but the umbers were kow i Idia over 2000 years ago. Fiboacci came upo the umbers while he was modelig a populatio of rabbits uder simplistic assumptios: we start with oe adult pair; a adult pair produces a pair of baby rabbits each moth; a baby rabbit becomes a adult after oe moth; the rabbits ever die. This model results i the Fiboacci recurrece relatio for the umber of adult pairs after moths (Figure -). The sequece goes like this:,, 2, 3, 5, 8, 3, 2, 34, ad so o. f represets the umber of adult pairs of rabbits at moth. The total umber of pairs of rabbits adults ad

5 .2 ~ RECURRENCE RELATIONS 9 babies is also a Fiboacci sequece, but it starts at p = ; p2 = 2, p = p + p 2,if > 2. = = 2 = 3 = 4 = 5... Copyright by Skylight Publishig Figure -. Rabbits populatio growth i the Fiboacci model. adult pair baby pair Fiboacci umbers have may iterestig properties. For example, the sequece of f+ ratios of cosecutive Fiboacci umbers r = coverges to the golde ratio f + 5 τ =.62. Fiboacci umbers pop up i various braches of mathematics 2 ad i the atural world (Figure -2; search the Iteret for fiboacci + ature for other examples).

6 92 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION Figure -2. Broccoli Romaesco. The umbers of clusters i the spirals form Fiboacci sequeces. Photograph by Madelaie Zadik, courtesy Botaic Garde of Smith College. Copyright by Skylight Publishig Exercises. Cosider a fuctio, if = f( ) = 2 f( ) +,if > What is f (4)? 2. A fuctio o positive itegers is described by, if = f( ) = f( ) + 2,if > Redefie it by a simple o-recursive formula. 3. Defie f( ) = 2 recursively, i terms of f( ), for all itegers.

7 .3 ~ RECURSION IN PROGRAMS Write a recursive defiitio of a fuctio f ( ) that has the followig properties: f() = 0, f(2) = 30, ad the values f(), f(2),..., f( ),... form a arithmetic sequece. 5. The same as Questio 4, but for a geometric sequece. 6. Describe the fuctio from Questio with a simple formula, without recursio. 7. Defie recursively, without factorials, the fuctio itegers 3.! f( ) = ( 3)! for 8. Give a =, a = a + for ay 2 o-recursive formula i terms of., describe a with a simple 9. Write a Pytho program that prompts the user to eter a positive iteger ad prits the first Fiboacci umbers. Copyright by Skylight Publishig 0. Fid a sequece that satisfies the Fiboacci equatio a = a + a 2,if > 2 ad, at the same time, is a geometric sequece with a =. How may such sequeces are there?.3 Recursio i Programs Now back to our favorite, s( ) = As we have see, the recursive, if = defiitio of s( ) is s ( ) =. Now suppose, just out of curiosity, s( ) +,if > we implemet this defiitio directly i a Pytho fuctio: def sumton(): if == : retur else: retur sumton(-) +

8 94 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION Will this work? What will sumton(5) retur? As you kow, i a program, a fuctio traslates ito a piece of code that is callable from differet places i the program. The caller passes to the fuctio some argumet values ad a retur address the address of the istructio to which to retur cotrol after the fuctio fiishes its work. So how ca this work whe a piece of code passes cotrol to itself? Wo t the program get cofused? Wo t Pytho choke tryig to swallow its ow tail? Ad yet it works! Try it: >>> sumton(5) 5 Because recursio is such a useful tool i programmig, the developers of Pytho (ad other programmig laguages) have made special efforts to esure it works. There are also CPU istructios that facilitate implemetig recursive calls. Copyright by Skylight Publishig Here is a allegory for what happes. Imagie a fuctio as a mail-order bakery. To place a order you take a empty box, put your writte order ito it ad also put i a label with your address, ad ship it to the bakery. The baker, call him Frak, receives the box, reads the order (the argumets you pass to the fuctio), bakes the cake you ordered, puts it i the box, attaches your label, ad ships the box back to you. Now suppose Frak has received a order ad is workig o it. Meawhile a ew order arrives. Frak immediately drops what he is doig, saves the ufiished cake (the values of the local variables) i the box the order came i, the puts the ew box that has just arrived o top of the oe he was workig o, opes the ew box, ad starts workig o that. Meawhile a ew order arrives. Frak immediately drops what he is doig, saves the ufiished cake (the values of the local variables) i the box the order came i, the puts the ew box that has just arrived o top of the oe he was workig o, opes the ew box, ad starts workig o that. Meawhile... You get the picture. The orders keep comig ad the boxes keep pilig up: ow there is a whole stack of them. Fially, at some poit, Frak gets a break: the orders stop comig. Frak fiishes the top order ad ships it to the customer. He the fiishes the oe that was just below it ad ships that to the customer. Ad so o, util he gets to the bottom of the stack, to the last remaiig order, fiishes that order, ad goes home. You might be woderig: Why is Frak processig orders i this fuy sequece? The order that came i last is completed first. Would t it be more fair to do it i a first-i-first-out maer? I a momet you will see why Frak does it his way.

9 .3 ~ RECURSION IN PROGRAMS 95 Oe day, Frak received a order for a multi-layered weddig cake with four layers. The layers i such a cake are basically the same, oly each layer is smaller i diameter tha the oe beeath it. Frak started workig o the bottom layer, but bega to worry that he d get cofused i all the layers. Luckily, a fried of his (a computer programmer) came up with this fabulous idea: why does t Frak sed a order to himself for a multi-layered cake that cosists of the three top layers, ad the, whe the three-layer cake is ready, just put it o top of the layer he is workig o? Frak does t have to ship his order very far, of course, but he still follows his usual procedure: takes a empty box, writes out a order for a three-layer cake, writes a label with the retur address (his ow) ad seds i the order (by puttig the box o the top of the stack). The as usual, he opes the box ad sees: aha, a order for a three-layer cake! So he writes himself a order for a two-layer cake. You get the picture. Fially Frak receives (his ow) order for a sigle-layer cake. He fiishes it quickly ad ships it back (to himself, of course). He receives it, uses it to complete the two-layer cake, ad ships that back (to himself). Receives it, completes the three-layer cake, ships back, receives that, completes the four-layer cake, ad fially ships it to the customer. Due to his LIFO (last-i-first-out) method, Frak utagles the whole layered busiess without ay cofusio. Copyright by Skylight Publishig This seems like a lot of shippig back ad forth, but it is easy for a computer. Pytho allocates a special chuk of memory, called a stack, for recursive fuctio calls. The CPU has the push istructio that puts a data item oto the top of the stack. The complemetary pop istructio removes ad returs the top item. I Pytho, Frak s activity may be represeted as somethig like this (assumig the + operator is properly defied for cakes): def bakesiglelayeredcake(d): 'Bakes a simple cake of diameter d' retur Cake(d) def bakemultilayeredcake(): 'Bakes a cake with layers' d = 3 * # the diameter of the bottom layer i iches cake = bakesiglelayeredcake(d) # Base case: == -- do othig # Recursive case: if > : cake += bakemultilayeredcake( - ) retur cake For a recursive fuctio to work, it must have a simple base case, where recursive calls are ot eeded.

10 96 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION I the above code, == is the base case. Whe a fuctio is called recursively, it must be called for smaller ad smaller tasks, which evetually coverge to the base case (or oe of the base cases). Each time we call the fuctio bakemultilayeredcake(-) recursively, we call it with a argumet that is smaller by tha the previous time. Recursio has its cost: first, you eed to have eough space o the stack ad, secod, the code speds extra time pushig ad poppig data ad callig the same fuctio. Iteratios are ofte more efficiet. But some applicatios, especially those dealig with ested structures or brachig processes, require a stack ayway, ad recursio allows you to write very cocise ad clear code. Example Write a recursive fuctio that calculates 0 for a o-egative iteger. Copyright by Skylight Publishig Solutio def pow0(): if == 0: # base case retur else: retur pow0(-) * 0 Example 2 Write a recursive fuctio that returs the sum of the digits i a o-egative iteger. Solutio def sumdigits(): s = % 0 # Base case: < 0 -- do othig # Recursive case: if >= 0: s += sumdigits( // 0) retur s

11 .3 ~ RECURSION IN PROGRAMS 97 Example 3 Write a recursive fuctio that takes a strig ad returs a reversed strig. Solutio def reverse(s): if le(s) > : s = reverse(s[:]) + s[0] retur s The base case here is implicit: whe the strig is empty or cosists of oly oe character, there is othig to do. A very popular example of recursio i computer programmig books ad tutorials is the Towers of Haoi puzzle. We have three pegs ad disks of icreasig size. Iitially all the disks are stacked i a tower o oe of the pegs (Figure -3). The objective is to move the tower to aother peg, oe disk at a time, without ever placig a bigger disk o top of a smaller oe. Copyright by Skylight Publishig Figure -3. The Towers of Haoi puzzle The key to the solutio is to otice that i order to move the whole tower, we first eed to move a smaller tower of - disks to the spare peg, the move the bottom disk to the destiatio peg, the move the tower of - disks from the spare peg to the destiatio peg (Figure -4).

12 98 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION Start: Move a smaller tower (recursio) : Move oe disk: Move a smaller tower (recursio) : Figure -4. A recursive solutio to Towers of Haoi Copyright by Skylight Publishig Example 4 Write a recursive fuctio that solves the Towers of Haoi puzzle for disks. Solutio def movetower(disks, frompeg, topeg): sparepeg = 6 - frompeg - topeg if Disks > : movetower(disks -, frompeg, sparepeg) prit('from ' + str(frompeg) + ' to ' + str(topeg)) # This code does ot model disk movemets # -- it just prits out each move if Disks > : movetower(disks -, sparepeg, topeg) If we wat to move a tower of, say, seve disks from peg to peg 2, a iitial call to movetower would be movetower(7,, 2).

13 .3 ~ RECURSION IN PROGRAMS 99 Note that i the above example the fuctio does ot retur a value (more precisely, it returs Noe), so it is a recursive procedure. Programmig this task without recursio would be rather difficult. Exercises. Write ad test a recursive fuctio that returs!. Do ot use ay loops. 2. I Sectio 5.3 Questio 7, you created a fuctio ittobi() that takes a o-egative iteger ad returs a strig of its biary digits. For example, ittobi(5) returs '0'. Rewrite this fuctio recursively, without ay loops. Hit: implemet two base cases: == 0 ad == : they cover the situatios whe has oly oe biary digit. 3. Write ad test a fuctio def pritdigits(): Copyright by Skylight Publishig that displays a triagle with rows, made of digits. For example, pritdigits(5) should display The fuctio s code uder the def lie should be three lies. Hit: prit *str() prits times. 4. The same as Questio 3, but ivert the triagle, so that pritdigits(5) prits Explai the statemet sparepeg = 6 - frompeg - topeg i Example 4.

14 200 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION 6. Idetify the base case i the movetower fuctio i Example Without ruig the code i Example 4, determie the output whe movetower(3,, 2) is called. 8. The Towers of Haoi puzzle was iveted by the Frech mathematicia Edouard Lucas i 883. The leged that accompaied the puzzle stated that i Beares, Idia, there was a temple with a dome that marked the ceter of the world. The Hidu priests i the temple moved golde disks betwee three diamod eedles. God placed 64 gold disks o oe eedle at the time of creatio ad the uiverse will come to a ed whe the priests have moved all 64 disks to aother eedle. What is the total umber of moves eeded to move a tower of 2 disks? 3 disks? 4 disks? disks? Assumig oe move per secod, estimate the lifespa of the uiverse..4 Mathematical Iductio Copyright by Skylight Publishig Let d be the umber of moves required to move a tower of disks i the Towers of Haoi puzzle. It is pretty obvious that, for >, d = d + + d = 2d +, because to move a tower of disks, we eed to first move a tower of - disks, the oe disk, the agai a tower of - disks. If you fiished the last exercise, you probably guessed correctly that d = 2. How ca we prove this fact more rigorously? I questios of this kid we ca use the method of proof called mathematical iductio. Suppose you have two sequeces, { a } ad { b } a. = b (base case).. Suppose that: 2. For ay > you have maaged to establish the followig fact: if a = b the a = b. Is it true the that a = b for all? Let s see: we kow that a = b. We kow that if a = b the a2 = b2. So we must have a2 = b2. Next step: we kow that a 2 = b 2. We kow that if a 2 = b 2 the a3 = b3. So we must have a3 = b3. Next step:... ad so o. We have to coclude that a = b for all. I the future, we do ot have to repeat this chai of

15 .4 ~ MATHEMATICAL INDUCTION 20 reasoig steps every time we just say our coclusio is true by mathematical iductio. Example Prove that the umber of moves i the Towers of Haoi puzzle for disks d = 2. Solutio d satisfies the relatioship d =, d = 2d + for > We wat to show that d = 2 for all. Copyright by Skylight Publishig. First let s establish the base case, =. d = ad 2 =, so OK. d = Now let s proceed with the iductio step. Assume that d = 2. The d = 2d + = 2(2 ) + = 2 2+ = 2. So, for ay >, we were able to show that if d = 2 the 2 d =. By mathematical iductio, d = 2 for all, Q.E.D. The method of mathematical iductio applies to ay sequece of propositios { P }. Suppose we kow that P is true; suppose we ca show for ay > that if P is true the P is true. The, by mathematical iductio, P is true for all. (I the above example, P is the propositio that d = 2.)

16 202 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION Sometimes it is ecessary to use a more geeral versio of mathematical iductio, with several base cases ad a more geeral iductio step. Suppose that:. P,..., P k are true (base case(s)). 2. For ay > k we ca prove that if P, P2,..., P are all true, the P is true. The, by mathematical iductio, P is true for all. Example 2 Prove that the -th Fiboacci umber f Solutio. We ca establish two base cases: Copyright by Skylight Publishig f = = = f = = Now the iductio step. Assume that for ay m< particular, for > 2, f ad f f m 3 2. The m 2. I f = f + f 2 + = + = > = So the propositio is true for the two base cases, ad if it is true for ad 2 the it is also true for. By math iductio, it is true for all, Q.E.D.

17 .4 ~ MATHEMATICAL INDUCTION 203 If you fiished Questio 9 from Sectio.2, you probably tried to prit the first 00 Fiboacci umbers ad got f 00 = The above result explais why Fiboacci umbers grow so fast. Exercises 2. Prove usig mathematical iductio that (2 ) =. 2. Cosider the followig fuctio: def tagle(s): = le(s) if < 2: retur '' # empty strig else: retur tagle(s[:]) + s[:-] + tagle(s[0:-]) Show that tagle('abcde') returs a strig that cotais either 'a' or 'e'. Copyright by Skylight Publishig 3. Show that for a strig s of legth, tagle(s), defied i Questio 2, returs a strig of legth 2 L =. Hit: first obtai a recurrece relatio for L, the prove it usig mathematical iductio. 4. Suppose you have straight lies i a plae, such that o two lies are parallel to each other ad o three lies go through the same poit. Show that the umber of regios ito which these lies cut the plae depeds oly o, but ot o a particular cofiguratio of the lies. Fid a formula for that umber ad prove it usig mathematical iductio. Hit: whe you add a lie, the existig lies cut it ito pieces. Each of these pieces cuts a regio ito two, addig a ew regio. 5. Cosider the sequece a0 = 2, a = 2, a = 2a + 3a 2 for 2. Write a Pytho program that prits out the first terms of this sequece. Examie the patter ad come up with a o-recursive formula for a, the prove that your guess is correct usig mathematical iductio. Hit: compare a to 3.

18 204 CHAPTER ~ RECURRENCE RELATIONS AND RECURSION 6. Cosider a recursive versio of the fuctio that returs the -th Fiboacci umber: def fiboacci(): if == or == 2: retur else: retur fiboacci(-) + fiboacci(-2) Test it with = 6 ad = 20. Now test it with = 00. The computer wo t retur the result right away. Perhaps the recursive versio takes a little loger... Prove by mathematical iductio that the total umber of calls to fiboacci, icludig the origial call ad all the recursive calls combied, is ot less tha the -th Fiboacci umber f. We have show above that 2 3 f. Assumig that your computer ca execute oe trillio calls per 2 secod, estimate how log you will have to wait for fiboacci(00) (i years). Press Ctrl-C to abort the program. As we said earlier, sometimes recursio ca be costly. Copyright by Skylight Publishig Terms itroduced i this chapter: Recurrece relatio Fiboacci umbers Golde ratio Recursio Recursive fuctio Recursive procedure Base case Mathematical iductio.5 Review Pytho feature itroduced i this chapter: Recursive fuctios

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

Recursive Procedures. How can you model the relationship between consecutive terms of a sequence?

Recursive Procedures. How can you model the relationship between consecutive terms of a sequence? 6. Recursive Procedures I Sectio 6.1, you used fuctio otatio to write a explicit formula to determie the value of ay term i a Sometimes it is easier to calculate oe term i a sequece usig the previous terms.

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

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

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

5.3 Recursive definitions and structural induction

5.3 Recursive definitions and structural induction /8/05 5.3 Recursive defiitios ad structural iductio CSE03 Discrete Computatioal Structures Lecture 6 A recursively defied picture Recursive defiitios e sequece of powers of is give by a = for =0,,, Ca

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

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

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

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

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

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

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

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

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

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

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

Module 8-7: Pascal s Triangle and the Binomial Theorem

Module 8-7: Pascal s Triangle and the Binomial Theorem Module 8-7: Pascal s Triagle ad the Biomial Theorem Gregory V. Bard April 5, 017 A Note about Notatio Just to recall, all of the followig mea the same thig: ( 7 7C 4 C4 7 7C4 5 4 ad they are (all proouced

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

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

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

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

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

Algorithm. Counting Sort Analysis of Algorithms

Algorithm. Counting Sort Analysis of Algorithms Algorithm Coutig Sort Aalysis of Algorithms Assumptios: records Coutig sort Each record cotais keys ad data All keys are i the rage of 1 to k Space The usorted list is stored i A, the sorted list will

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

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

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

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

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

UNIT 1 RECURRENCE RELATIONS

UNIT 1 RECURRENCE RELATIONS UNIT RECURRENCE RELATIONS Structure Page No.. Itroductio 7. Objectives 7. Three Recurret Problems 8.3 More Recurreces.4 Defiitios 4.5 Divide ad Coquer 7.6 Summary 9.7 Solutios/Aswers. INTRODUCTION I the

More information

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8) CIS 11 Data Structures ad Algorithms with Java Fall 017 Big-Oh Notatio Tuesday, September 5 (Make-up Friday, September 8) Learig Goals Review Big-Oh ad lear big/small omega/theta otatios Practice solvig

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

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

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

1. The lines intersect. There is one solution, the point where they intersect. The system is called a consistent system.

1. The lines intersect. There is one solution, the point where they intersect. The system is called a consistent system. Commo Core Math 3 Notes Uit Day Systems I. Systems of Liear Equatios A system of two liear equatios i two variables is two equatios cosidered together. To solve a system is to fid all the ordered pairs

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

Examples and Applications of Binary Search

Examples and Applications of Binary Search Toy Gog ITEE Uiersity of Queeslad I the secod lecture last week we studied the biary search algorithm that soles the problem of determiig if a particular alue appears i a sorted list of iteger or ot. We

More information

Big-O Analysis. Asymptotics

Big-O Analysis. Asymptotics Big-O Aalysis 1 Defiitio: Suppose that f() ad g() are oegative fuctios of. The we say that f() is O(g()) provided that there are costats C > 0 ad N > 0 such that for all > N, f() Cg(). Big-O expresses

More information

15-859E: Advanced Algorithms CMU, Spring 2015 Lecture #2: Randomized MST and MST Verification January 14, 2015

15-859E: Advanced Algorithms CMU, Spring 2015 Lecture #2: Randomized MST and MST Verification January 14, 2015 15-859E: Advaced Algorithms CMU, Sprig 2015 Lecture #2: Radomized MST ad MST Verificatio Jauary 14, 2015 Lecturer: Aupam Gupta Scribe: Yu Zhao 1 Prelimiaries I this lecture we are talkig about two cotets:

More information

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer Departmet of Computer ciece Columbia Uiversity olutios to Fial COM W45 Programmig Laguages ad Traslators Moday, May 4, 2009 4:0-5:25pm, 309 Havemeyer Closed book, o aids. Do questios 5. Each questio is

More information

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering EE 4363 1 Uiversity of Miesota Midterm Exam #1 Prof. Matthew O'Keefe TA: Eric Seppae Departmet of Electrical ad Computer Egieerig Uiversity of Miesota Twi Cities Campus EE 4363 Itroductio to Microprocessors

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

SD vs. SD + One of the most important uses of sample statistics is to estimate the corresponding population parameters.

SD vs. SD + One of the most important uses of sample statistics is to estimate the corresponding population parameters. SD vs. SD + Oe of the most importat uses of sample statistics is to estimate the correspodig populatio parameters. The mea of a represetative sample is a good estimate of the mea of the populatio that

More information

1.8 What Comes Next? What Comes Later?

1.8 What Comes Next? What Comes Later? 35 1.8 What Comes Next? What Comes Later? A Practice Uderstadig Task For each of the followig tables, CC BY Hiroaki Maeda https://flic.kr/p/6r8odk describe how to fid the ext term i the sequece, write

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

Visualization of Gauss-Bonnet Theorem

Visualization of Gauss-Bonnet Theorem Visualizatio of Gauss-Boet Theorem Yoichi Maeda maeda@keyaki.cc.u-tokai.ac.jp Departmet of Mathematics Tokai Uiversity Japa Abstract: The sum of exteral agles of a polygo is always costat, π. There are

More information

Lecture 5: Recursion. Recursion Overview. Recursion is a powerful technique for specifying funclons, sets, and programs

Lecture 5: Recursion. Recursion Overview. Recursion is a powerful technique for specifying funclons, sets, and programs CS/ENGRD 20 Object- Orieted Programmig ad Data Structures Sprig 202 Doug James Visual Recursio Lecture : Recursio http://seredip.brymawr.edu/exchage/files/authors/faculty/39/literarykids/ifiite_mirror.jpg!

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

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

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway. Bjare Stroustrup www.stroustrup.com/programmig Chapter 5 Errors Abstract Whe we program, we have to deal with errors. Our most basic aim is correctess, but we must deal with icomplete problem specificatios,

More information

Lecture 7 7 Refraction and Snell s Law Reading Assignment: Read Kipnis Chapter 4 Refraction of Light, Section III, IV

Lecture 7 7 Refraction and Snell s Law Reading Assignment: Read Kipnis Chapter 4 Refraction of Light, Section III, IV Lecture 7 7 Refractio ad Sell s Law Readig Assigmet: Read Kipis Chapter 4 Refractio of Light, Sectio III, IV 7. History I Eglish-speakig coutries, the law of refractio is kow as Sell s Law, after the Dutch

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

TUTORIAL Create Playlist Helen Doron Course

TUTORIAL Create Playlist Helen Doron Course TUTORIAL Create Playlist Hele Doro Course TUTY Tutorial Create Playlist Hele Doro Course Writte by Serafii Giampiero (INV SRL) Revised by Raffaele Forgioe (INV SRL) Editio EN - 0 Jue 0-0, INV S.r.l. Cotact:

More information

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5 Morga Kaufma Publishers 26 February, 28 COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 5 Set-Associative Cache Architecture Performace Summary Whe CPU performace icreases:

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

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

27 Refraction, Dispersion, Internal Reflection

27 Refraction, Dispersion, Internal Reflection Chapter 7 Refractio, Dispersio, Iteral Reflectio 7 Refractio, Dispersio, Iteral Reflectio Whe we talked about thi film iterferece, we said that whe light ecouters a smooth iterface betwee two trasparet

More information

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria.

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria. Computer Sciece Foudatio Exam August, 005 Computer Sciece Sectio A No Calculators! Name: SSN: KEY Solutios ad Gradig Criteria Score: 50 I this sectio of the exam, there are four (4) problems. You 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

EVALUATION OF TRIGONOMETRIC FUNCTIONS

EVALUATION OF TRIGONOMETRIC FUNCTIONS EVALUATION OF TRIGONOMETRIC FUNCTIONS Whe first exposed to trigoometric fuctios i high school studets are expected to memorize the values of the trigoometric fuctios of sie cosie taget for the special

More information

n n B. How many subsets of C are there of cardinality n. We are selecting elements for such a

n n B. How many subsets of C are there of cardinality n. We are selecting elements for such a 4. [10] Usig a combiatorial argumet, prove that for 1: = 0 = Let A ad B be disjoit sets of cardiality each ad C = A B. How may subsets of C are there of cardiality. We are selectig elemets for such a subset

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity Time CSE 47: Algorithms ad Computatioal Readig assigmet Read Chapter of The ALGORITHM Desig Maual Aalysis & Sortig Autum 00 Paul Beame aalysis Problem size Worst-case complexity: max # steps algorithm

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

Protected points in ordered trees

Protected points in ordered trees Applied Mathematics Letters 008 56 50 www.elsevier.com/locate/aml Protected poits i ordered trees Gi-Sag Cheo a, Louis W. Shapiro b, a Departmet of Mathematics, Sugkyukwa Uiversity, Suwo 440-746, Republic

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

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

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

Ch 9.3 Geometric Sequences and Series Lessons

Ch 9.3 Geometric Sequences and Series Lessons Ch 9.3 Geometric Sequeces ad Series Lessos SKILLS OBJECTIVES Recogize a geometric sequece. Fid the geeral, th term of a geometric sequece. Evaluate a fiite geometric series. Evaluate a ifiite geometric

More information

Inductive Definition to Recursive Function

Inductive Definition to Recursive Function PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 1 Iductive Defiitio to Recursive Fuctio PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 2 Factorial Fuctio Cosider the followig recursive defiitio of the factorial

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

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

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

New Results on Energy of Graphs of Small Order

New Results on Energy of Graphs of Small Order Global Joural of Pure ad Applied Mathematics. ISSN 0973-1768 Volume 13, Number 7 (2017), pp. 2837-2848 Research Idia Publicatios http://www.ripublicatio.com New Results o Eergy of Graphs of Small Order

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

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

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer Data structures DATA STRUCTURES Static problems. Give a iput, produce a output. Ex. Sortig, FFT, edit distace, shortest paths, MST, max-flow,... amortized aalysis biomial heaps Fiboacci heaps uio-fid Dyamic

More information

Mathematical Stat I: solutions of homework 1

Mathematical Stat I: solutions of homework 1 Mathematical Stat I: solutios of homework Name: Studet Id N:. Suppose we tur over cards simultaeously from two well shuffled decks of ordiary playig cards. We say we obtai a exact match o a particular

More information

Chapter 4 The Datapath

Chapter 4 The Datapath The Ageda Chapter 4 The Datapath Based o slides McGraw-Hill Additioal material 24/25/26 Lewis/Marti Additioal material 28 Roth Additioal material 2 Taylor Additioal material 2 Farmer Tae the elemets that

More information

1&1 Next Level Hosting

1&1 Next Level Hosting 1&1 Next Level Hostig Performace Level: Performace that grows with your requiremets Copyright 1&1 Iteret SE 2017 1ad1.com 2 1&1 NEXT LEVEL HOSTING 3 Fast page loadig ad short respose times play importat

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

Intro to Scientific Computing: Solutions

Intro to Scientific Computing: Solutions Itro to Scietific Computig: Solutios Dr. David M. Goulet. How may steps does it take to separate 3 objects ito groups of 4? We start with 5 objects ad apply 3 steps of the algorithm to reduce the pile

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

An (or ) is a sequence in which each term after the first differs from the preceding term by a fixed constant, called the.

An (or ) is a sequence in which each term after the first differs from the preceding term by a fixed constant, called the. Sectio.2 Arithmetic Sequeces ad Series -.2 Arithmetic Sequeces ad Series Arithmetic Sequeces Arithmetic Series Key Terms: arithmetic sequece (arithmetic progressio), commo differece, arithmetic series

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

Sorting 9/15/2009. Sorting Problem. Insertion Sort: Soundness. Insertion Sort. Insertion Sort: Running Time. Insertion Sort: Soundness

Sorting 9/15/2009. Sorting Problem. Insertion Sort: Soundness. Insertion Sort. Insertion Sort: Running Time. Insertion Sort: Soundness 9/5/009 Algorithms Sortig 3- Sortig Sortig Problem The Sortig Problem Istace: A sequece of umbers Objective: A permutatio (reorderig) such that a ' K a' a, K,a a ', K, a' of the iput sequece The umbers

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

the beginning of the program in order for it to work correctly. Similarly, a Confirm

the beginning of the program in order for it to work correctly. Similarly, a Confirm I our sytax, a Assume statemet will be used to record what must be true at the begiig of the program i order for it to work correctly. Similarly, a Cofirm statemet is used to record what should be true

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

Pattern Recognition Systems Lab 1 Least Mean Squares

Pattern Recognition Systems Lab 1 Least Mean Squares Patter Recogitio Systems Lab 1 Least Mea Squares 1. Objectives This laboratory work itroduces the OpeCV-based framework used throughout the course. I this assigmet a lie is fitted to a set of poits usig

More information

Name Date Hr. ALGEBRA 1-2 SPRING FINAL MULTIPLE CHOICE REVIEW #1

Name Date Hr. ALGEBRA 1-2 SPRING FINAL MULTIPLE CHOICE REVIEW #1 Name Date Hr. ALGEBRA - SPRING FINAL MULTIPLE CHOICE REVIEW #. The high temperatures for Phoeix i October of 009 are listed below. Which measure of ceter will provide the most accurate estimatio of the

More information

On Infinite Groups that are Isomorphic to its Proper Infinite Subgroup. Jaymar Talledo Balihon. Abstract

On Infinite Groups that are Isomorphic to its Proper Infinite Subgroup. Jaymar Talledo Balihon. Abstract O Ifiite Groups that are Isomorphic to its Proper Ifiite Subgroup Jaymar Talledo Baliho Abstract Two groups are isomorphic if there exists a isomorphism betwee them Lagrage Theorem states that the order

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

3D Model Retrieval Method Based on Sample Prediction

3D Model Retrieval Method Based on Sample Prediction 20 Iteratioal Coferece o Computer Commuicatio ad Maagemet Proc.of CSIT vol.5 (20) (20) IACSIT Press, Sigapore 3D Model Retrieval Method Based o Sample Predictio Qigche Zhag, Ya Tag* School of Computer

More information