MySQL is open source. All the algorithms are free. The only difficulty is getting them in a readable form.
Sasha Pachev's book, Understanding MySQL Internals, briefly discusses the deadlock detection algorithm. It's a good place to start before diving into the source code.
This was first published in July 2007