Block 1: Introduction and Basic Concepts Flashcards
Define an algorithm
A specific procedure for solving a specific task
5 things that impact the running time of a program
> programming language > hardware > pattern > size of the input data > algorithm used
what does f(n) = O(g(n)) roughly mean?
f(n) < c * g(n), for some constant c, large enough n
describe the model we use for reasoning about program speed?
> 1 CPU core (single thread)
sequential
primitive operations take unit time
define running time
the number of steps it takes to finish for data of size n.
Worst Case
the longest time the algorithm takes for size n
Best Case
the shortest time the algorithm takes for size n
Average Case
the expected time for size n
O(f(n)) (big-oh)
upper-bound: time(n) < c * f(n)
Ω(f(n)) (omega)
lower bound: time(n) > c * f(n)
Θ(f(n)) (theta)
upper and lower bound
Big-oh of selection sort
O(n^2)
Worst case of insertion sort
O(n^2)
Best case of insertion sort
O(n)
Big oh of merge subroutine
O(n)
Big oh of mergesort
O(nlogn)