Space and Time Hacks
- Answer and Explanation
- Answer/ Explanation
- Answer/ Explanation
- Answer/ Explanation
- Explanation
- Explanation
- Explanation
- Explanation
- Explanation
- Explanation
a = 0
b = 0
for i in range(N):
a = a + random()
for i in range(M):
b= b + random()
a = 0;
for i in range(N):
for j in reversed(range(i,N)):
a = a + i + j;
k = 0;
for i in range(n//2,n):
for j in range(2,n,pow(2,j)):
k = k + n / 2;
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
a = 0
i = N
while (i > 0):
a += i
i //= 2
Which of the following best describes the useful criterion for comparing the efficiency of algorithms?
How is time complexity measured?
for i in range(n):
i=i*k
value = 0;
for i in range(n):
for j in range(i):
value=value+1
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.