The algorithm remembers the things you've looked at. Based on what you've looked at, it guesses what type of person you are. You are now grouped with other people that it thinks is like you. Then it looks at other people in this group, and it sees what they've looked at. If it finds something that you haven't looked at yet, it'll show that to you.
Generally speaking, this works because if someone who has similar interests likes something, there's a good chance you'll like it too. The unintended side effect (or intended side effect, depending on your perspective) is that you're likely to be only shown things that conform to your current perspective, which can amplify biases and skew your perception of what's going on in the world