#### Category : time-complexity

I am finding a solution either in python or java to find the intersection between 2 lists. In python, we can use (sets/lists) etc In java, we can use (ArrayList) etc Or we can use HashSet also. But I am not able to understand which approach should we use. In hash sets, we have less ..

Say we use 2 functions in one go: sorted(list(str_variable)) – Python uses Timsort which has a complexity of NlogN – so then the overall complexity of this becomes: N^2*logN It’d be considered as a function inside a function and so the complexities will get multiplied (O(N) for list() and O(NlogN) for the sort(). But I ..

I am trying to find no of combinations possible using given array elements which is less than given no n. Example : Input: digits = ["1","3","5","7"], n = 100 Output: 20 The 20 numbers that can be written are: 1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, ..

Code total_exc_time = 0 for _ in range(10): start = time.time() set_a = set() dict_a = dict() add = set_a.add for index in range(1000000): dict_a[index] = index add(index) total_exc_time += ((time.time() – start) * 1000) total_exc_time = 0 for _ in range(10): `start = time.time()` `dict_a = dict()` for index in range(1000000): dict_a[index] = index ..

This code computes a^b.. But I am not sure about its complexity def powerFunc(a,b): if b==1: return a elif b==0: return 1 else: return a*powerFunc(a,b-1) a=int(input()) b=int(input()) print(powerFunc(a,b)) Source: Python-3x..

If there are no other loops inside of that while loop, is it possible to have O(n^2) runtime? Source: Python..

For a set. What is the time complexity for next(iter(S))? Any proof? I know that iter() turns an iterable into iterator and suppose next() is O(1). Source: Python-3x..