New course! Every coder should learn Generative AI!
Try a free lesson0
How do you easily measure the time complexity of an algorithm?
Hey guys! I am trying to figure out if this code is correct and how can I measure the time complexity of it, please check, give me your feedback and answer my question: https://code.sololearn.com/cZE4E1iWG0Tb/#py P.D: I am studying that subject, please also help with a good page with information about and how can I measure it without going counting line per line with differents inputs. If you like the code, please upvote. Otherwise, tell me what can I improve.
3 Answers
+ 3
Rosana Rodrรญguez Milanรฉs hi,
๐ I'll give you the most basic information and assign one unit to every statement and at last summation of all statement units an basic complexity is calculated which is space complexity
๐ if any loop is their in any statement then assign that loop with the number of times that loop is executing like if an loop is going to n time to run then you can assign them with n unit
๐ then if their any nested loop then that inner loop with n unit and outer loop with n unit and if nested loop is their then assign n*n to the statement
๐ if function are their then assign function with the statement that are present in that function if that has 5 statements then assign 5 to that function and the time that which the function is calling
Have these ๐ ๐ ๐ ๐ ๐
+ 4
๐ complexity can be calculated in three notation like
๐ BigOh(O) notation
๐ Theta(ฮฆ) notation
๐ omega(ฮ ) notation
Every notation is calculated and defined according to worst case and the best case and average case complexity
๐ this link will help about calculate complexity
https://www.hackerearth.com/practice/basic-programming/complexity-analysis/time-and-space-complexity/tutorial/
๐ https://medium.com/@.RT/total-n00bs-guide-to-big-o-big-%CF%89-big-%CE%B8-aa259ae8a1c2
+ 3
Here is an lesson about that which is quite good explanation
https://www.sololearn.com/learn/6362/?ref=app
If you have any further query ping me I'll loved to answer with some example
https://www.sololearn.com/learn/6362/?ref=app
Have these ๐ ๐ ๐ ๐