Should I include a research in my thesis which does not have a direct connection to its title? Let's say that my Ph.D. project was about mitigating the problem X (e.g. analyzing the specific type of datasets) from different perspectives (CS field), for which one of the methods I have developed was algorithm A. 

However, I also developed the algorithm B, which belongs to the same overarching category that also Algorithm A belongs to, but it does not apply to problem X. 

Even though I also published Algorithm B as an individual conference paper, I'm not sure if I can bring it in my dissertation. It is a novel method, but not related to the main problem (or the dataset type) that my Ph.D. project is about. So, I'm not sure if I can include it in my Ph.D. thesis despite the time I spent developing it.
In many cases, it comes down to your defense and the work you've done, and the thesis is a document for you. You can include, or not include whatever work you want.

I'm speaking from a PhD in the natural sciences in the US, different countries and subjects have different rules and guidelines.