Week 1 Flashcards
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 Ω do?
Tells us that the time taken grows at least by this function.
What does Θ notation do?
Tight bound, gives a minimum running time k1 * N and a maximum running time k2 * N.
Summarize difference between Big Θ, Big Oh and Big Omega.
Θ (N^2) must have N^2 only as biggest.
O(N^2) must have N^2 or lower as biggest.
Ω (N^2) must have N^2 or larger as biggest.
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
Shell Sort
Quick Sort
List sorting algorithms that are non-recursive.
Selection Sort
Insertion Sort
Shell Sort
List sorting algorithms that utilize comparisons.
Selection Sort
Insertion Sort
Shell Sort
Merge Sort
Quick Sort
List sorting algorithms that are internal.
Selection Sort
Insertion 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.