Videos
I have a function that takes an array, then sorts it and iterates over every item.
Iโm trying to understand why the Time complexity is O(nlogn) instead of O(n+logn) or O(n). Why is n being multiplied together with logn when they are two separate steps?
My thought process is that if it takes 10ms (logn) to sort the array and then 100ms (n) to search it, then the overall time is 110ms (n+logn) not 1000ms (nlogn). And because 100ms is much greater than 10ms, I can simplify it to just 100ms or O(n)
What is time complexity of crating an array in Python?
Example: a = [0] * 10
It's O(n). When used on an iterable (like a Set), Array.from iterates over the iterable and puts every item returned into the new array, so there's an operation for every item returned by the iterable.
It is always going to be O(n) as the number of iterations would be directly proportional to the number of elements in the set. Actual Time complexity would be O(n) for retrieving values from a set O(n) for pushing into an array.
O(n) + O(n) = O(2n)
But since we do not consider a constant value when calculating using n value it should be O(n).