Recurrence Relations Flashcards
QuickSort
QS(n) = QS(s-left) + QS(right - s) + O(n), n = right - left
partitioning around a pivot
O(nlogn)
QuickSort best case
theta (nlogn)
QuickSort worst case
theta (n^2)
QuickSort average case
theta (nlogn)
QuickSelect average case
C(n) = C(n/2) + (n+1)
theta (n)
QuickSelect worst case
theta (n^2)
Closest Pairs
sorting: O(nlogn)
splitting: T(n/2)
T(n) = 2T(n/2) + O(nlogn)
T(n) = O(n (logn)^2 )
BFS running time
O(n)
or O(edges + nodes)
DFS running time
O(n) or O(edges + nodes)
Topological Sort
O (n)
O (m+n)
Heap operations
Insert: O (log n)
extract min: O (log n)
find min: O (1)
heapify O(n)
delete: O( log n )
Heapsort
O(nlogn)
Dijkstra’s
O (edge + vertices*log (vertices) )
runtime: 0 (#edges * #vertices)
max weight independent set
maxVal(i) = max {maxVal(i - 1), maxVal(i-2) + Ci}
for gap of 2: max {maxVal(i - 1), maxVal(i - 2), maxVal(i - 3) + Ci}
weighted path
totCost(i, j) = max {totCost (i - 1, j), totCost (i, j - 1)} + Cij
knapsack
V (n, w) = max { V ( n-1, w ), V ( n - 1, W - Wn ) + Vn }
long increasing subsequence in 1d array
F (k) = max (i < k) and (xi < xk) { F (i) } + 1
longest common subsequence
if s1i = s2i: LCS ( i, j ) = LCS ( i - 1, j - 1 ) + 1
if s1i NOT = s2i: LCS ( i, j ) = max { LCS ( i - 1, j ) , LCS ( i, j - 1) }
optimal binary search tree
C [i, j] = min {C [i, k + 1], C [k + 1, j]} + sum of probabilities up to j (pic in text chain)