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.
Dig Deeper on Linux servers
Related Q&A from Scott Noyes
Get suggestions for choosing MySQL character sets and field collations from expert Scott Noyes. Continue Reading
A MySQL expert describes two ways that the multi-master support can be used. Continue Reading
MySQL expert Scott Noyes explains why using mysqli over mysql_functions allows you to take advantage of MySQL's newer features and PHP scripts. Continue Reading