Algorithms Flashcards
What is runtime
A function f: N -> N, which maps the input size to the number of elementary operations completed
How to compare asymptotic complexity of functions
What is the racetrack principle
How does Fast Peak Finding work
Imagine the array is sloping downwards, then there must be a peak to the left and vice versa; perform binary search to get the peak
Log laws
n = 2^log(n) (base 2)
Derivative of log(n) (base 2)
Sum of arithmatic sequence formula
Sum of geometric sequence formula
What is big O notation
Runtime complexity hierarchy
How to prove/disprove that a function is in O(n)
Composing two functions effect on O notation
Loop / multiplying functions effect on O notation
Loop / multiplying functions effect on O notation
What are the 5 steps of merge sort
1) If n = 1 return A
2) Recursively sort left sub-array
3) Recursively sort right sub-array
4) Merge together the two arrays
5) Return the sorted array
How does the tree diagram of merge sort look like
What are the steps of a divide and conquer algorithm
1) Divide into smaller subproblems
2) Conquer sub-problems
3) Merge back up the tree to find a general solution
What does it mean for an algorithm to be in-place
It means that no auxillary arrays are used. At most O(1) elements stored outisde array
What does it mean for an algorithm to be stable
The ordering of elements are not un-neededly swapped. Ex: If A[i] = A[i+1] they will not be swapped. Useful for satilite data
Is insertion sort stable and in-place
Insertion sort is both stable and in-place
Is merge sort stable and in-place
Merge sort is stable but not in-place since it uses auxillary arrays in the merge step
How does the merge step work in mergesort (4 steps)
Require both halves of A are sorted
1) Copy left half into auxillary array B
2) Copy right half into auxillary array C
3) Merge B and C in sorted order
4) Return result
How is a loop represented in sigma notation
What type of binary tree is mergesort
Complete binary tree