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)
Comment for queries if any and upvote if u like it.
Thank you.
Get Answers For Free
Most questions answered within 1 hours.