Statement 3:
In an equation, when n grows larger the lower order terms in the equation have the least effect on the running time of the algorithm.
Even a small fraction of the highest order term is enough to dominate the lower order terms when n is large enough. In general when we calculate algorithms running times we ignore the lower order terms and the coefficient of highest order term as they have a very minimal effect when n is large.
So from the given two equations if we ignore lower order terms and coefficient of the highest order term. So the equations we got
1)n5log3n (We ignored 10n2 as it is a lower order term) (Algorithm A)
2)n6 (We ignored 17 coefficient of n6 and lower order term n4log7n) (Algorithm B)
We know that logn is faster than n.
We can write above two equations like below
1)n5 * log3n
2) n5 * n
So clearly the first equation i.e. n6 is greater than the second equation i.e. n5log3n and takes more time to run. Therefore Algorithm A is faster than Algorithm B
STATEMENT 3: Algorithm A takes n log, (n) + 10na elementary operations and algorithm B takes...
Design an algorithm for the following description. Solution can
be done in pseudo-code or steps of the algorithm.
Describe and analyze an algorithm that takes an unsorted array A of n integers (in an unbounded range) and an integer k, and divides A into k equal-sized groups, such that the integers in the first group are lower than the integers in the second group, and the integers in the second group are lower than the integers in the third group,...
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...
Need to find number of elementary expressions in terms
of n, not looking for Big O complexity.
4. Work out the number of elementary operations in the worst possible case and the best possible case for the following algorithm (justify your answer): 0: function Nonsense (positive integer n) 1: it1 2: k + 2 while i<n do for j+ 1 to n do if j%5 = 0 then menin else while k <n do constant number C of elementary operations...
What does a run-time analysis usually countS pts a. The number of arithmetic and other operations required fot the b. The number of megabytes required for the program to run c. The number of seconds required for the program to run. d. The number of seconds plus the number of megabytes Total 100 points, 30 ins and other operations required for the program to rn 2. What do we call an input that results in the longest execution timet a....
Question 2 Consider the following algorithm Fun that takes array A and key Kas Fun(AO,...,n - 1], K) count = 0 for i = 0 ton - 1 do for j = i +1 to n - 1 do if A[i] + A[j] == K then count = count +1 end if end for end for return count What is the best case time complexity of the above algorithm?! (log(n)) O(1) (n) (na) Previous o H H 9
9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...
3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n < 4) 10; return n+ else f SillyCalc(Ln/4) answer Num Num 10 for (i-2; i<=n-1; i++) Num + = answer + answer; answer return answer } Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2*...
This BubbleSort algorithm takes as its input the list of "words" w), W2, ...,W.. Step 1: Let j=1. Step 2: If j=n then output the list wi, W2, ...,Wn Step 3: Set k=n-1 Step 4: If wx+1 <wk, then swap the values of wk and wx+1 Step 5: If k>j, then replace k by k-1 and go to step 4. Step 6: Replace j by j +1 Step 7: Go to step 2 Find a function which gives the total...
(1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an integer between 1 and n. (2) Suppose Algorithm-1 does f(n) = n**2 + 4n steps in the worst case, and Algorithm-2 does g(n) = 29n + 3 steps in the worst case, for inputs of size n. For what input sizes is Algorithm-1 faster than Algorithm-2 (in the worst case)? (3) Prove or disprove: SUM{i**2} [where i changes from i=1 to i=n] ϵ tetha(n**2)....
Subject: Algorithm
solve only part 4 and 5 please.
need urgent.
1 Part I Mathematical Tools and Definitions- 20 points, 4 points each 1. Compare f(n) 4n log n + n and g(n)-n-n. Is f E Ω(g),fe 0(g), or f E (9)? Prove your answer. 2. Draw the first 3 levels of a recursion tree for the recurrence T(n) 4T(+ n. How many levels does it have? Find a summation for the running time. (Extra Credit: Solve it) 3. Use...