The algorithm is pretty simple: show random videos, select categories that invoke the most reaction, show more random videos from those categories and so on. That's why the algorithm often converges to a local maximum and keeps showing disturbing shit on one topic.