How do I calculate/show proof of the worst run time for an algorithm?
:-D There's an entire field of CS dedicated to figuring out the time complexity of an algorithm! http://en.wikipedia.org/wiki/Analysis_of_algorithms A bunch of different methods are in there, but you can try this one http://en.wikipedia.org/wiki/Analysis_of_algorithms#Evaluating_run-time_complexity
So, there are some basic counting methods involved in this, so you could do a basic count analysis of a routine. def does_something(string name) pint 'hi ' + name; end The above would be an O(1) operation, because no matter the input provided it will always take the same amount of time to execute. On the other hand... the following: def print_array_items(Array[string] arrayOfStrings) foreach arrayOfStrings as individual item print individualItem; endforeach end That would be O(n), meaning that the time increasing linearly based on the size of the arrayOfStrings. You can count this by figuring out what determines how many times the loop will run.
Join our real-time social learning platform and learn together with your friends!