Algorithmic Techniques#
Prefix Sum#
Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
---|---|---|---|---|---|---|---|
1 |
6 |
4 |
2 |
5 |
3 |
- |
|
0 |
1 |
7 |
11 |
13 |
18 |
21 |
Prefix sum can be calculated in by the below formula:
Now, the sum of the elements of from to can be computed using:
Using the prefix sum array, the same can be
Example should make it more clearer:
Using prefix sums:
Read more at: https://usaco.guide/silver/prefix-sums and https://labuladong.gitbook.io/algo-en/iii.-algorithmic-thinking/prefix_sum
Backtracking#
Types of problems
Decision - Search for a solution.
Optimization - Search for best solution.
Enumeration - Find all possible/feasible solutions.