- Algorithms: http://www.cs.usfca.edu/~galles/visualization/Algorithms.html
- Sorting: https://www.toptal.com/developers/sorting-algorithms/
- A few small manual tests.
- A test for each possible type of answer (smallest answer, biggest answer, answer doesn’t exist, etc.)
- Test for time/memory limit: generate a test with the largest possible size of input (“max test”), run your program, measure time and memory consumption.
- Tests for corner cases:
- Smallest possible “n”: the length of the input sequence or string, the number of queries, etc.
- Equal numbers, equal letters in the string, more generally, equal objects in the input. Any two objects that are not restricted to be different in the problem statement can be equal.
- Largest numbers in the input allowed by the problem statement – for example, to test for integer overflow.
- Degenerate cases like empty set, three points on one line, a tree which consists of just one chain of nodes.
Implement two different solutions, one correct and fast, other a significantly different(perhaps even brute force) and compare the solutions obtained from both using random numbers for test cases. This significantly reduces failure and is guaranteed to give you edge test cases. Stress Testing is considered as last resort!
- It is very important to write programs that work correctly on all the allowed inputs.
- Testing is essential to writing correct programs.
- First test on a few small manual tests, then test for each type of answer, then test on large test cases for time limit and memory limit, then test on corner cases.
- After that, apply stress testing to ensure your program works – it will almost always lead to correct solution. You can do it before your first attempt to submit your solution – and will often get it right from the first attempt!
- Stress testing consists of implementing the intended solution, another simple possible slow solution, a test generator and an infinite loop which generates tests and compares answers of the two solutions.
- Always try to find the smallest test cases on which your solution fails.
- Try different regions of the test space when generating cases for stress testing.
Add images for the increasing run-times for different complexities as well as limits of n.
nth Fibonnaci number= Approximately (n/5) digits
- Make a greedy choice
- Prove that this choice is a safe move
- Break problems into sub-problems
- Iterate over each sub problem
- Estimate running time
General Example- Line, Points, covered by segments
A move is called a safe move if there is an optimal solution consistent with this first move.
Before solving any algorithm, try and covert it into a mathematical problem.
Divide and Conquer
- Break into non-overlapping subproblems of same kind
- Solve sub-problems
- Combine results
Solving using Recursion, we have:
- Create a recursive solution
- Define a corresponding recurrence relation using T(n)
- Determine worst case runtime T(n)
- Optionally, create iterative solution
Run time of binary search is Theta(N)
Normal polynomial multiplication= O(n^2)
Karatsuba polynomial multiplication= O(n^1.58)
For multiplying very large numbers using the Karatsuba algorithm, make x=10 and construct appropriate polynomial from the numbers.
- Maximum number of leaves in a tree of depth d ==> d>=log(2) L, where L is the number of leaves
- log(n!) = Omega( n* log n)
- String similarity using reward, penalty for mismatch and insertions
- Longest Common Subsequence
- Edit Distance problem
- Minimizing edit distance= Maximizing Alignment Score
- Knapsack Problem
- Polynomial Multiplication- Naive and Karatsuba
- Solve UNIONSET- JUNE17 question using Bit Masking
- Develop Intro Sort–> Develop Heap Sort
- Watch Coding Blocks Seminar, revise Greedy vs DP
- Revise Divide and Conquer paradigm
- Implement Doubly Linked Lists
- Section 10.1 and 10.2 CLRS for Data Structures.