Question

Find Big-O Notation 1. def upper_triangle(A, N): # Assume A is a square matrix (stack of...

Find Big-O Notation

1.
def upper_triangle(A, N): # Assume A is a square matrix (stack of lists)
for i in range(N):
A[i][:i] = [0 for _ in range(i)]
return A

2.
def running_avg(vec, N):
sum = 0
avg_list = []
for i in range(N):
sum += vec[i]
avg = sum / (i + 1)
avg_list.append(avg)
return avg_list

3.
def similarity(vec1, vec2, N): # Assume vec1 and vec2 have length of N
s1 = 0
s2 = 0
for i in range(N):
if vec1[i] in vec2:
s1 += 1
if vec2[i] in vec1:
s2 += 1
return (s1 + s2) / (2 * N)

4.
def sample_var(vec, N):
def mean(vec, N):
sum_arr = 0
for i in range(N):
sum_arr += vec[i]
return sum_arr / N
var_arr = 0
for i in range(N):
var_arr += (vec[i] - mean(arr, N)) ** 2
return var_arr / (N - 1)

Homework Answers

Answer #1

Comment for queries if any and upvote if u like it.

Thank you.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using Big O notation, indicate the time requirement of each of the following tasks in the...
Using Big O notation, indicate the time requirement of each of the following tasks in the worst case. Computing the sum of the first n even integers by using a for loop            [ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)          Displaying all n integers in an array            [ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)          Displaying all n integers in a sorted linked chain            [ Choose...
Given T(n)= T(n-1) + 2*n, using the substitution method prove that its big O for T(n)...
Given T(n)= T(n-1) + 2*n, using the substitution method prove that its big O for T(n) is O(n^2). 1. You must provide full proof. 2. Determine the value or the range of C.
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward solutions. One of those problems is the “Maximum Subarray Sum” or “Maximum Value Contiguous Subsequence": Given a sequence of n numbers A[0 ... n-1], give an algorithm for finding a contiguous subsequence A[i ... j], for which the sum of elements in this subsequence is the maximum we can get by choosing different i or j.   For example: the maximum subarray sum for the...
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return...
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return the length of the longest chain of 1's that start from the beginning. You MUST use a while loop for this! We will check. >>> longest_chain([1, 1, 0]) 2 >>> longest_chain([0, 1, 1]) 0 >>> longest_chain([1, 0, 1]) 1 """ i = 0 a = [] while i < len(submatrix) and submatrix[i] != 0: a.append(submatrix[i]) i += 1 return sum(a) def largest_rectangle_at_position(matrix: List[List[int]], x:...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
a)Assume that you are given a matrix A = [aij ] ∈ R n×n with (1...
a)Assume that you are given a matrix A = [aij ] ∈ R n×n with (1 ≤ i, j ≤ n) and having the following interesting property: ai1 + ai2 + ..... + ain = 0 for each i = 1, 2, ...., n Based on this information, prove that rank(A) < n. b) Let A ∈ R m×n be a matrix of rank r. Suppose there are right hand sides b for which Ax = b has no solution,...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
Prove that for a square n ×n matrix A, Ax = b (1) has one and...
Prove that for a square n ×n matrix A, Ax = b (1) has one and only one solution if and only if A is invertible; i.e., that there exists a matrix n ×n matrix B such that AB = I = B A. NOTE 01: The statement or theorem is of the form P iff Q, where P is the statement “Equation (1) has a unique solution” and Q is the statement “The matrix A is invertible”. This means...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT