Week 1 Flashcards
(89 cards)
What is an algorithm?
A step-by-step procedure for solving a problem using a computer program.
What is a procedure?
Method to solve the problem.
Is a programming language a type of procedure?
Nope.
Why do we analyze algorithms?
To predict performance, provide guarantees and understand theoretical basis.
What are the limitations of run-time analysis?
- Implementing the algorithm may be difficult.
- Doesn’t include all possible inputs.
- Only valid on same software environments and hardware.
How much time to primitive operations take?
Constant time.
If a perform a primitive operation many times what is the time taken?
N where N is the number of times.
Define O(1), O(log N), O(N), O(N log N)
O(1) = constant time regardless of input
O(log N) = logarithmic time, proportional to the logarithmic of the input size.
O(N) = linear time, directly proportional to input size.
O(N log N) = log-linear time, proportional to the logarithmic of the input size times the input size.
Why is Big O notation desirable?
Abstracts away implementation details as we expect every algorithm to have a run time proportional to its big O notation across every OS.
What is O of O(N) + O(N^2)?
O(N^2)
How can I find the value of n for which the Big-Oh notation holds? Use example 11n + 5 to explain.
We take the big O representation O(x) and express c * x >= 1 / 2 * (original equation). The value of n is the point where it holds.
What does big Ω, Θ and O do?
Omega: The algorithm will take at least this time.
O: The algorithm will never take more than this time.
Theta: The algorithm takes exactly this time (within constants)
Summarize difference between Big Θ, Big Oh and Big Omega using N^2 time.
Θ (N^2) takes N^2
O(N^2) N^2 max
Ω (N^2) N^2 min
Explain briefly selection sort.
Iterate through the list from i to find smallest entry and swap with i. Then increment i and repeat till end of list.
List sorting algorithms that are in-place?
Selection Sort
Insertion Sort
Bubble Sort
Shell Sort
Quick Sort
List sorting algorithms that are non-recursive.
Selection Sort
Bubble Sort
Insertion Sort
Shell Sort
Counting Sort
Radix Sort
List sorting algorithms that utilize comparisons.
Selection Sort
Insertion Sort
Bubble Sort
Shell Sort
Merge Sort
Quick Sort
List sorting algorithms that are internal.
Selection Sort
Insertion Sort.
Bubble Sort
Shell Sort
Quick Sort
List sorting algorithms that are external?
Merge Sort
List sorting algorithms that are unstable.
Selection Sort
Shell Sort
Quick Sort
Explain stability in relation to sorting algorithms.
Stable sorting algorithms preserve the existing relative order of elements when comparing equal keys.
Explain internal vs external in relation to sorting algorithms.
- Internal sort is one where the items being sorted can be kept in main memory / RAM.
- External sort is one where the items being sorted need to use external memory.
Explain insertion sort?
In iteration i, swap a[i] with each larger entry on its left. Iterate through full list until every element has been inserted in correct place.
List Sorting algorithms that are stable.
Insertion Sort
Bubble Sort
Merge Sort
Counting Sort
Radix Sort