Notes on correct solutions fro h8 (after it was graded). Worst-case versus best-case running time - Some algorithms always have the same speed, so worst-case and best-case are the same - Some algorithms an be significantly faster or slower depending on the precise values of input - Selection sort - always the same, best-case = worst-case - Binary search, linear search - best-case is finding what you're looking for right away Binary search - Running time is log2(n), logarithm with base 2 - Is not n/2. n/2 is how many numbers are "removed from consideration" after 1 step! if you keep removing 1/2 of the remaining #s after each step, it takes log2(n) steps to get to a single number left to check. Sorting algorithms - Selection sort - fairly easy to understand, but too slow for large lists + Other quadratic time sorts - bubble, insertion, and many others - Python's list.sort - fairly complicated (timsort, assignment mistakenly said it used quicksort), fast even for large lists + Other n*log(n) time sorts - quick sort, merge sort Measuring running time with time command - real time is time on the clock, and depends on what else is happening on the computer (if lots of stuff running, real time is longer) - user time is time CPU executed for your program, which should be mostly the same regardless of what else is running - sys time is time the OS did things for your program (write to the screen, read from storage, etc.) - if program used multiple cores (4 say), real time could be 1 minute while user time could be 4 minutes - user time would take into account time spent by all cores - for very fast programs (less than a second or few), you can't really compare the running times - anything less than a second is "nearly instant" and could be anything less than a second each time you run it Formulas for best/worst case - Big-O formulas "ignore" constant factor because the precise running time depends on which computer you run program on. - Selection sort, one formula is n*(n-1)/2, and another is n*(n+1)/2. Those are slightly different, but only by some constant factor. So if you gave either of those as answers, they are both O(n**2) and correct. The precise details do matter, but the most important feature of the running time is that it is quadratic. Long-running programs - If you killed it after 15 minutes, then you would say the running time was > 15 minutes, and the # steps was ?? - Even if program never finished, if you have a formula for the running time you should still say what that formula would give. Anagrams - 10 character anagrams - ask the internet, check the program