#!/usr/bin/env python # coding: utf-8 # # Analyzing how fast algorithms run # We always care about how fast an algorithm runs and try to come up with clever ways of having faster algorithms. # # We use a notation called big **O** notation to analyze how fast an algorithm runs, and how it scales when its input grows. We often focus on the worst case sceanrio. I.e. what happens if you have an input that makes the algorithm run as slow as possible? (e.g. we saw this in binary search when we analyzed the maximum number of steps it takes us to guess a number) # ## O(1) # In[ ]: #assigning a variable L=range(1000) L[0]=5 #doesn't matter how big L is L[10]=10 # ## O(n) linear time # # In[28]: #e.g. for loops x=[1,5,3,2,30,30,22] min_val=x[0] for i in x: if i