Skip to content Skip to sidebar Skip to footer

Time Complexity Of Checking Whether A Set Is Contained In Another Set

I am trying to implement the example of finding the shortest substring of a given string s containing the pattern char. My code is working fine, but my goal is to attain the time c

Solution 1:

Per docss.issubset(t) is the equivalent of s <= t meaning that during the operation it will test if every element in s is in t.

Best scenario: if s is the first element of t -> O(1)

Worst case scenario: if s in the last element of t -> O(len(t))

That is for isubset. For the list comprehension :

j for j in d is O(n) for getting each key

if d[j]>0 is O(n) for comparing each value of dictionary d

Here you can find more info.

Post a Comment for "Time Complexity Of Checking Whether A Set Is Contained In Another Set"