Question

In: Computer Science

A) What is the big O for the following: f(n)=5n2+logn+1 i)n^2 ii)1 iii)logn iv)5n2+logn+1 B) Given...

A) What is the big O for the following:

f(n)=5n2+logn+1

i)n^2

ii)1

iii)logn

iv)5n2+logn+1

B) Given two algorithms with the following running time:Algorithm

A: Ta(n)=4n+20 andAlgorithm

B: Tb(n)=2n2+10Which of the following statements are correct?

i)Algorithm A is faster than algorithm B for n > 100.

ii)Algorithm B is faster than algorithm A for n > 100.

C) A function template can operate with:

i)an integer

ii)any type of data

iii)a string

iv)a Rectangle object

Solutions

Expert Solution

Answer A:

f(n) = 5n^2 + logn + 1

i) O(n^2) , because in a function f(n) = 5n^2 + logn + 1, n^2 provides the upper bound of the function. In simple words, n^2 is bigger than logn and 1 at any value of n.

Answer B:

i) Algorithm A is faster than algorithm B for n > 100

Explanation:

Ta(n)=4n+20

Tb(n)=2n^2+10

Now check the value of both the algorithms at a value greater than 100, let n = 110

Ta(n)=4n+20

Ta(n) = 4(110) + 20 = 440 + 20 = 460

Tb(n)=2n^2+10

= 2(110)^2 + 10 = 2 * 12,100 + 10 = 24,200 + 10 = 24,210

Here 460 < 24,210 that means algorithm A takes 460 time and Algortihm B take 24,210 time. Hence Algorithm A is faster than Algorithm B because Algorithm A takes less time than B.

Answer C:

ii)any type of data, Function templates that may deal for generic forms are feature models. This enables one to build a prototype of functions whose features can be applied to more than one type or class without repeating the whole code for each type.


Related Solutions

8. Use the following table to answer questions I, ii, iii and iv A B C...
8. Use the following table to answer questions I, ii, iii and iv A B C Initial cost $15,000 $9,000 $12,000 Annual benefit $8,000 $2,000 $1,800 Salvage value $5,000 $9,000 0 Life in years 2 years 3 Years Infinity MARR 10% i. The NPW of alt. A is __________________. A) $13,420 B) $17,380 C) $11,000 D) $6,00 ii. The NPW of alt. B is __________________. A) $13,420 B) $17,380 C) $11,000 D) $6,000 iii. The NPW of alt. C is...
1.)Prove that f(n) = O(g(n)), given: F(n) = 2n + 10; g(n) = n 2.)Show that...
1.)Prove that f(n) = O(g(n)), given: F(n) = 2n + 10; g(n) = n 2.)Show that 5n2 – 15n + 100 is Θ(n2 ) 3.)Is 5n2 O(n)?
2014 I 31 2017 I 69 II 24 II 54 III 23 III 46 IV 16...
2014 I 31 2017 I 69 II 24 II 54 III 23 III 46 IV 16 IV 32 2015 I 42 2018 I 82 II 35 II 66 III 30 III 51 IV 23 IV 38 2016 I 53 2019 I 91 II 45 II 72 III 39 III 59 IV 27 IV 41 Create a multiple regression equation incorporating both a trend (t=0 in 2013: IV) and dummy variables for the quarters. Let the first quarter represent the reference...
2014 I 31 2017 I 69 II 24 II 54 III 23 III 46 IV 16...
2014 I 31 2017 I 69 II 24 II 54 III 23 III 46 IV 16 IV 32 2015 I 42 2018 I 82 II 35 II 66 III 30 III 51 IV 23 IV 38 2016 I 53 2019 I 91 II 45 II 72 III 39 III 59 IV 27 IV 41 Create a multiple regression equation incorporating both a trend (t=0 in 2013: IV) and dummy variables for the quarters. Let the first quarter represent the reference...
1. The general formula of alkanes is: (i) CnH2n+2 (ii) CnH2n-2 (iii) CnH2n (iv) CnH2n+4 (v)...
1. The general formula of alkanes is: (i) CnH2n+2 (ii) CnH2n-2 (iii) CnH2n (iv) CnH2n+4 (v) Cn+2H2n 2. The name of the following compound is: a. Tetrabenzene b. Chrysene c. Coronene d. Anthracene e. Pyrene 3. To achieve noble gas configuration, hydrogen requires………………..whereas chlorine requires…………………in outermost shell. a. Octet, duet b. Singlet, duet c. Duet, octet d. Octet, singlet e. None of the above 4. The ……………. the number of relatively stable resonance contributors, the …………… the resonance energy. a....
In Toxicity and Hypersensitivity, What are the differences between Types I, II,III, and IV hypersensitivities including
In Toxicity and Hypersensitivity, What are the differences between Types I, II,III, and IV hypersensitivities including why they occur and cells (mechanisms) they utilize
Describe the insertion of type I, II, III and IV into the ER membrane? Differences?
Describe the insertion of type I, II, III and IV into the ER membrane? Differences?
Explain the following in relation to antiretroviral therapy: i. Pharmacodynamics ii. Pharmacokinetics iii. Pharmacogenomics iv. Drug...
Explain the following in relation to antiretroviral therapy: i. Pharmacodynamics ii. Pharmacokinetics iii. Pharmacogenomics iv. Drug availability during contraception use and pregnancy v. Drug-drug interactions during treatment
explain the following Neurotransmitters: i. Serotonin ii. Histamine iii. Dopamine ( 5 marks each ) iv....
explain the following Neurotransmitters: i. Serotonin ii. Histamine iii. Dopamine ( 5 marks each ) iv. Glycine v. Glutamate vi. Gama amino butyric acid (GABA) vii. Nitric oxide (NO)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT