If you post ore than 1 question, then as HOMEWORKLIB RULES guidelines I just have to answer one question.
1.
function Fibonnaci(n):
{
// first term of series
if n == 0
return 1
if n == 1
return 2
a = 1
b = 2
for i <- 2 to n
{
c = a + b
a = b
b = c
}
return b
}
The above function computes n th fibonnaci number in
O(n) Time Complexity
and O(1) Space Complexity
It is so because the above function checks the two conditions for n == 0 and n == 1 in O(1) time.
The for loop runs for n - 2 times.
Hence, Time Complexity = O(1) + O(1) + O(n - 2)
= O(n - 2) (as O(1) is negligible)
= O(n) (as (n - 2) = n if n is very large)
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci...
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...
Consider the function FINDDUPLICATES(A[0. 1) that returns a list of all duplicate items in the unsorted integer array A of size n. For example, given the array |3, 2, 4, 3], the function should return the value 3. For the array 11 2,3 5,5,5,66,81, the function should return an array (or list) 5,6 In this task, you will develop two alternative solutions for the FINDDUPLICATES(Ao..n 1 func- tion. In your implementations, you may call any of the algorithms introduced in...
Please answer this in python pseudocode. It's an algorithm question. 1. [10 marks] Consider the function SumKSmallest(A[0..n – 1), k) that returns the sum of the k smallest elements in an unsorted integer array A of size n. For example, given the array A=[6,-6,3,2,1,2,0,4,3,5] and k=3, the function should return -5. a. [3 marks) Write an algorithm in pseudocode for SumKSmallest using the brute force paradigm. Indicate and justify (within a few sentences) the time complexity of your algorithm. b....
6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...
Need help with 1,2,3 thank you. 1. Order of growth (20 points) Order the following functions according to their order of growth from the lowest to the highest. If you think that two functions are of the same order (Le f(n) E Θ(g(n))), put then in the same group. log(n!), n., log log n, logn, n log(n), n2 V, (1)!, 2", n!, 3", 21 2. Asymptotic Notation (20 points) For each pair of functions in the table below, deternme whether...
Question2 0/5 pts If exact running time of an algorithm is T(n)-5n3+ n2 + 3n -5 where n is the input size, then which of the following is true? T(n)- O(n) RCOECEQuestion 3 0/5 pts Which of the following is the correct ranking of the functions listed below: logn. n2 n2n, 2. 1500. nlogn, 5 Question 4 5/5 pts to search
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...
Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...
I understand how it was simplified to n^(∈/(sqrt(logn))), but I'm trying to understand how to prove that logn grows faster for 0<∈<1. The derivative seems too complicated to prove this via Lhopital's Rule, so I tried using WolframAlpha to compare the two with logn as the numerator: http://www.wolframalpha.com/input/?i=limit+as+n+approaches+infinity+(logn)%2F(n%5E(0.5%2F(sqrt(logn))))&rawformassumption=%7B%22FunClash%22,+%22log%22%7D+-%3E+%7B%22Log10%22%7D However, this gives me a result of 0 for any value above 0, which would mean that n^(∈/(sqrt(logn))) grows at a faster rate, even when 0<∈<1. When I try to graph it,...
For each of the following problems write a recurrence relation describing the running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution using substitution and carefully computing lower and upper bounds for the sums. Simplify and express your answer as Θ(n k ) or Θ(n k (log n)) wherever possible. If the algorithm takes exponential time, then just give exponential lower bounds. 5. func5 (A,n) /*...