It surprised me to learn that algorithms can be patented. If that's the case, why aren't famous algorithms like Dijkstra's algorithm patented? More importantly, how would they be enforced - wouldn't you need to look at the source code of all suspicious programs?

An abstract algorithm -- such as Dijkstra's algorithm -- cannot be patented (in the US or most other jurisdictions). On the other hand, a specific application of an algorithm -- e.g., a machine that performs a particular chemical transformation on a product by means of a set of computer instructions -- is likely patentable (subject to other considerations, such as novelty and non-obviousness). See Diamond v. Diehr (1981) and more recently Bilski v. Kappos (2010) and Alice Corp. v. CLS Bank International (2014).
–
user4545Mar 17 at 18:47

Mathematical / Algorithmic / Abstract Concept patents, AND/OR methods for calculating / performing them are only available in a limited number of territories (but the list includes the: USA, JPN, KOR, AUS, SGP), most jurisdictions expressly forbid any attempt to patent or copyright a purely abstract concept or algorithm.
Anyway numerous famous algorithms have obtained a US patent, or have outstanding applications covering their calculation eg.