a = 0
b = 0
for i in range(N):
  a = a + random()
 
for i in range(M):
  b= b + random()

Answer and Explanation

The answer to this is O(N + M) time, O(1) space; this is because the times are being added and the value is only to find 1 leaving this as a correct answer declaring the vairable and getting to answer i.

a = 0;
for i in range(N):
  for j in reversed(range(i,N)):
    a = a + i + j;

Answer/ Explanation

The answer for this is O(N*N) this is beu case since n is i and n,i is the range it makes 0+ n +N-1 giving a root leading to this answer

k = 0;
for i in range(n//2,n):
  for j in range(2,n,pow(2,j)):
        k = k + n / 2;

Answer/ Explanation

The answer is O(nLogn) this is buecase it refers to the breaking down the code and somethign to the power of something = log meaning this would be the most logical answer itterated through the loop.

What does it mean when we say that an algorithm X is asymptotically more efficient than Y?

Answer/ Explanation

X will always be a better choice for large inputs This is the answer becuase asymptomatically means when apporcahing a large or small function wihtin math leaving it to work

a = 0
i = N
while (i > 0):
a += i
i //= 2

Explanation

The answer is O(log N) beucaese you get a log value thorught this fucntion as its something to the power of something = something

Which of the following best describes the useful criterion for comparing the efficiency of algorithms?

Explanation

  • Both time and memory are needed as that is what gets you to a good algorithm meaning its is the basis of time/space

How is time complexity measured?

Explanation

By counting the number of primitive operations performed by the algorithm on a given input size. This complexity has to do with algorithms and meaning within an input the algorithm is measured and so are operations within in

for i in range(n):
i=i*k

Explanation

  • xO(logkn) this is beucase of the loop of i and n giving the out put this
value = 0;
for i in range(n):
for j in range(i):
	value=value+1

Explanation

  • The answer is n(n-1), meaning that n is n-1 however I am not sure as the loop is a bit confusing and adds so I dont understand the subtraction

The Big-O notation provides an asymptotic comparison in the running time of algorithms. For n < n0​​, algorithm A might run faster than algorithm B, for instance.

Explanation

False;The Big-O notation provides an asymptotic comparison in the running time of algorithms. For n < n0​​, algorithm A might run faster than algorithm B, for instance.