How do they figure out what time complexity of an algorithm is? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How do they figure out what time complexity of an algorithm is?

The time complexity submitted by the community is good, but , do I really have to cram it up to master the algorithms?

20th Jul 2018, 8:50 AM
Prashant Soni
Prashant Soni - avatar
1 ответ
+ 2
Having an awareness is sufficient. Just think about what happens if the size of the operation increases. Adding to a list when you know where the tail is would be constant, it doesn't matter about the size of the list, it would take the same time each time. Searching for an element in a list would be O(n) - the operation will generally take more time for a longer list. When you start having nested for loops you start getting into n^2, because if you double the size you quadruple the potential time taken. There are good resources around but generally bearing these points in mind is sufficient, depending on your task of course
20th Jul 2018, 9:49 AM
Dan Walker
Dan Walker - avatar