I'm trying to understand how Stockfish thinks, how it calculates the best move. I'm reading open source code, but it's not clear. I want to know, should I know some theory about algorithms to understand that code? Or is it possible without knowing anything? If there are important algorithms, please tell me what I should learn before reading source code.
If you are reading the code to become a better player, you won't have much luck. The tricks used are only useful when you have the memory and computational power of a machine.
If instead you are reading it to learn about chess programming, the following wiki is a great resource https://chessprogramming.wikispaces.com
TSCP is well commented and a good place to learn how chess programs work http://www.tckerrigan.com/Chess/TSCP/