0

Should we consider the time complexity of inbuilt functions and operations

Say I have a list and what to find an element: I could do this: if element in list: .......... Or I could write my own binary search function: So how do I know the time complexity of (in)

2nd Oct 2021, 6:32 AM
Richard
Richard - avatar
3 Réponses
+ 1
Every algorithm has its own time complexity. But here is one of many websites that tell you time complexity of the most common algorithms: https://www.bigocheatsheet.com/
2nd Oct 2021, 7:38 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Time complexity of "element in list" is O(n) as it is just a linear search... (you could also know its just a linear search as it works with unsorted lists too).. So if you want your code to operate quicker, you might consider making your own binary search function.
2nd Oct 2021, 6:59 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Aleksei Radchenkov is there a website where I can find a list of the time complexities
2nd Oct 2021, 7:14 AM
Richard
Richard - avatar