Attribution Non-Commercial (BY-NC)

16 views

Attribution Non-Commercial (BY-NC)

- 2-7-Guided-Notes-SE-Solving-Proportions.pdf
- Guide Data Structures Concise Intro Using Java
- Teaching Mathematics Survival Skills
- BigO
- Intel Math Brochure
- vedic_maths_2
- teaching kennesaw
- Eyptian Multiplication
- math day 5-friday
- Complexity ret
- Fun With Facts
- Week 9 homework packet 13-14.docx
- 3-31 area in relation to addition and multiplication teacher resources
- PDF
- Conditioning Algorithms for Exact and Approximate Inference in Causal Networks
- Juan González-Meneses- Conjugacy problems in braid groups and other Garside groups Part 3
- tric
- vedic-mathematics-tricks.pdf
- Algorithm Lecture 1
- book talk presentation- each orange has 8 slices

You are on page 1of 3

2.1 In the test case b = 2, n = 11, the simple power algorithm performs 11 multiplications, while the smart power algorithm performs 7 multiplications. Algorithm 1.1 has time complexity O(1). The matrixAdd method performs n2 additions. Its time complexity is O(n2). The matrixMult method performs n3 additions and n3 multiplications. Its time complexity is O(n3). 2.5 To analyze Algorithm 2.16, count the number of characters required to render i to base r. If i is positive, the number of characters is logr i + 1. If i is negative, the number of characters is logr(abs(i)) + 2 (the extra character being ). The time complexity is O(log(abs(i))). To print a given integer i to base r: 1. Set s to the empty string . 2. Set p to the absolute value of i. 3. Repeat the following until p = 0: 3.1. Let d be the digit corresponding to (p modulo r). 3.2. Prepend d to s. 3.3. Divide p by r. 4. If i < 0, prepend to s. 5. Print s. 6. Terminate. This algorithms time complexity is O(log(abs(i))). 2.7 To find the GCD of positive integers m and n (recursive version): 1. Let p be the greater and q the lesser of m and n. 2. If p is a multiple of q: 2.1. Terminate with answer q. 3. If p is not a multiple of q: 3.1. Let g be the GCD of q and (p modulo q). 3.2. Terminate with answer g. 2.8 Algorithm 2.21 performs n multiplications. Its time complexity is O(n). Method to calculate the factorial of n (recursive version):

static int factorial (int n) { if (n == 0) return 1; else return n * factorial(n-1); }

2.2 2.4

2.6

To calculate the factorial of n (non-recursive version): 1. Set f to 1. 2. For i = 1, , n, repeat: 2.1. Multiply f by i. 3. Terminate with answer f. Method to calculate the factorial of n (non-recursive version):

2-1

static int factorial (int n) { int f = 1; for (int i = 1; i <= n; i++) f *= i; return f; }

2.9

Let the Fibonacci function be fib(n). Tabulate the first few Fibonacci numbers, and the ratios of consecutive numbers:

n fib(n) fib(n)/fib(n1) 0 1 1 1 1.00 2 2 2.00 3 3 1.50 4 5 1.67 5 8 1.60 6 13 1.63 7 21 1.62 8 34 1.62

Thus we can see that fib(n) cbn, where b 1.62 and c 0.72. Suppose that Algorithm 2.22 performs adds(n) additions. It is easy to see that adds(n) = fib(n) 1 cbn 1. The algorithms time complexity is therefore O(bn). To calculate the Fibonacci number of n (non-recursive version): 1. If n 1: 1.1. Terminate with answer 1. 2. If n > 1: 2.1. Set oldfib to 1, and set fib to 1. 2.2. For i = 2, , n, repeat: 2.2.1. Set oldfib and fib to fib and oldfib+fib, respectively. 2.3. Terminate with answer fib. Method to calculate the Fibonacci number of n (recursive version):

static int fibonacci (int n) { if (n <= 1) return 1; else return fibonacci(n-1) + fibonacci(n-2); }

static int fibonacci (int n) { if (n <= 1) return 1; else { int oldfib = 1, fib = 1; for (int i = 2; i <= n; i++) { int newfib = oldfib + fib; oldfib = fib; fib = newfib; } return fib; }

2.10

Outline of program:

2-2

static void moveTower (int n, int source, int dest) { if (n == 1) moveDisk(source, dest); else { int spare = 6 - source - dest; moveTower(n-1, source, spare); moveDisk(source, dest); moveTower(n-1, spare, dest); } } static void moveDisk (int source, int dest) { System.out.println("Move disk from " + source + " to " + dest); }

To make the program count the moves, modify moveTower to return the required number of moves, as follows:

static int moveTower (int n, int source, int dest) { if (n == 1) { moveDisk(source, dest); return 1; } else { int spare = 6 - source - dest; int moves1 = moveTower(n-1, source, spare); moveDisk(source, dest); int moves2 = moveTower(n-1, spare, dest); return moves1 + 1 + moves2; } }

2-3

- 2-7-Guided-Notes-SE-Solving-Proportions.pdfUploaded byDulce Castro
- Guide Data Structures Concise Intro Using JavaUploaded byasadfx
- Teaching Mathematics Survival SkillsUploaded bymmink
- BigOUploaded byShearyar Khan
- Intel Math BrochureUploaded byHaman Salem
- vedic_maths_2Uploaded bygauravchandok
- teaching kennesawUploaded byapi-241990487
- Eyptian MultiplicationUploaded byoneluckyclover2
- math day 5-fridayUploaded byapi-235613269
- Complexity retUploaded byjoaquinedes
- Fun With FactsUploaded byFaisal Risor Legacy
- Week 9 homework packet 13-14.docxUploaded byHeather Wenrich Hodges
- 3-31 area in relation to addition and multiplication teacher resourcesUploaded byapi-267171155
- PDFUploaded bygot2win
- Conditioning Algorithms for Exact and Approximate Inference in Causal NetworksUploaded byhenderson
- Juan González-Meneses- Conjugacy problems in braid groups and other Garside groups Part 3Uploaded byjsdmf223
- tricUploaded byRakhi Rajput
- vedic-mathematics-tricks.pdfUploaded bysharif1974
- Algorithm Lecture 1Uploaded byArnabi Modak
- book talk presentation- each orange has 8 slicesUploaded byapi-253211499
- bocaUploaded byohudalharthi
- Maths Tests and Answers 0Uploaded bybabu karu
- Assign 03Uploaded byarunabh bhattacharya
- CS 110itemsUploaded bysdfhgwerhywerhdsfh
- makenna kaitlyn lesson plan session 5Uploaded byapi-336009980
- lessons1-5Uploaded byapi-286783416
- Ejerc. 4Uploaded byOmaira Naileth Ortiz Aguirre
- Geometría analiticaUploaded byfugaperu
- gcdUploaded byshadabghazali
- chap2Uploaded byCristi Popa

- Lardo 2018 IOP Conf. Ser. Earth Environ. Sci. 125 012011Uploaded byDevi Masila
- skenario 1,2,3,4Uploaded bysepta afifin
- FCC BCC MicrostructureUploaded byfirarizki
- CRS DocumentUploaded bySalmanFatehAli
- Demantra Installation Guide for Release 7314 August21 2012Uploaded byinfyrajayaar
- 3D Seismic Study to Investigate the Structural and Stratigraphy of Mishrif Formation in Kumiat Oil Field_Southern_Eastern IraqUploaded byIJAERS JOURNAL
- Review of VectorsUploaded byhaalefom
- AT89C51Uploaded byRoad Ad
- CAT_3516B-2250_ENUploaded byMohammed Jassim
- Triggers in BESAUploaded bytobylj5227
- 1Classification and performance of ceramic insulatorsUploaded by严晨倩
- JPowerSources2014 251 152 GiacomoUploaded byRafael Serpa
- Lsf7 Release NotesUploaded byKarol Korytkowski
- OpenSeesUploaded bykmilo098
- Ctc Manufacture 1Uploaded byDayarathne Ranasinghe
- Wcn Complete 123 UnitsUploaded byBhargav Dundi
- Datasheet DCU20 V4-0Uploaded byCristiana Maria
- Chapter 4 Screw ThreadsUploaded byDishank Upadhyay
- 1.Pipe and Tube SizingUploaded bywidhisaputrawijaya
- Lessons in Electric Circuits- Volume IVUploaded bySorin.Renghea
- Pengelolaan DM tipeb2Uploaded byBetty Imamala
- Class A1A6Uploaded bySalim
- Problem Solving - Simultaneous Equations (Shu Ying & Jing Jie)Uploaded byEdwin Tan Pei Ming
- Dress Pos Hart-svi-II-AP Manual 9Uploaded byAmarnath Yadav
- List of Dimensionless NumberUploaded byFebio Dalanta
- ASTM D 4138 - 94Uploaded byCyril Angki
- Perkins Engine No GuideUploaded byMhd
- A Hybrid System Approach to Impedance and Admittance ControlUploaded byawright261934mi
- 87172577 Operation Research 2nd SemUploaded byPankaj Pareek
- 000-015 ExamUploaded byMicheleCahill