So as I was going through some practice problems from programming contests (ACM ICPC, etc), people can often times take an O(N^2) Solution, or even worse, and use a Heap (priority_queue in C++) or a deque to reduce complexity. (as some sort of optimization, after noticing "something" in the pattern)
For example in the "sliding window maximum" problem, which is pretty much:
For each window of size K in an array of size N, compute the maximum.
There's a trivial O(NK) algorithm, a rather easy O(nlogn) solution (even I can see it, using a heap) and a O(N) solution, using a double ended queue.
These principals seem to be on the principal of "throwing" away useless values, or querying a region to find a property (maximum, cumulative sum, min, etc).
For example to convert some O(N^2) algorithms to O(NlogN), sometimes you can use a priority_queue and keep popping out values until you get one within a certain window, instead of looping through all previous N elements to find a maximum.
Anyone have good tips? (Other than doing more problems... I'm trying to do that)