What is the time complexity of the code below?
import math
arr1 = [2,3,5,6]
arr2 = [1,4,7,8,9,10,21]
for i in range(len(arr2)):
#some operations
for i in range(len(arr1)):
for j in range(2,int(math.sqrt(arr1[i]))):
#some operations
Is O(n+m*q), where n is size of arr2 and m is size of arr1 correct? Can I simplify it? I just want to know what the complexity is when we searching for all elements in array then for all elements in another array we compute sqr(n) operations.
O(n + m * sqrt(k)), where:nis the length ofarr2;mis the length ofarr1;kis the maximum number inarr1.sqrt(k)is the same ask**(1/2), so it's sublinear and therefore cannot be simplified to justk.You may find more complete answers in the Computer Science Stack Exchange.