Algorithms Flashcards
Week 2.7, 2.8, 2.9 (78 cards)
sum of arithmetic series
a1 + (n - 1)d
sum of geometric permutations
(a1(1 - r^n))/(1 -r)
number of permutations
n!
number of k-combinations
n1/(n - k)!k!
log inequality
log2 n <= n
pseudocode I/O
input/output operations - brief descriptions
pseudocode for arrays of fixed size
A[0 … n-1]
pseudocode !=
pseudocode <=
pseudocode assignment
i <- 1
pseudocode if condition
if i < n
…
else
…
pseudocode for loops
for i <- 1 to n do
pseudocode for while loops
i <- 1
while i < n do
…
i <- i + 1
resource constraints of algorithms
- space
- time
algorithm cost of solution
amount of resources a solution consumes
empirical analysis of algorithms
- using methods like gmtime() to get the actual running time
- actual running time of an algorithm depends on computer used
- data collected gives an idea how running time grows when input size grows
theoretical analysis of algorithms
- analytical approach aimed at estimating the time complexity of the running time of algorithm based on the pseudocode
- time complexity (or running time) of an algorithm in the RAM model is the total number of basic operations for each possible problem instance as a function of the size of the instance
- worst-case instance considered when analysing time complexity
while loop with n/2 iterations
i <- 1
while i <= n do
…
i <- i + 2
pseudocode nested loops
for i <- 1 to n do
for j <- 1 to n do
pseudocode dependent nested loops
for i<- 1 to n do
for j <- 1 to i do
iterations of a dependent nested loop
1/2 x n(n + 1)
2 basic principles of complexity analysis
- consider a dominating term - low-order ignored
- ignore multiplitive constants
log2n loop
i <- 1
while i < n do
…
i <- i * 2
OR
i <- 1
while i < n do
…
i <- i/2
describe big-O
- worst-case efficiency
- worst-case instances of size n
- asymptotic upper bound for a given function