Hook

Their other posts in the index, biggest breakout first.
Let's do a little code hard. And it is hard for a reason, but we're going to figure it out together. Hi, I'm Tara. I'm a senior software engineer and I used to teach computer science at Carnegie Melon. So, this is alien dictionary. And basically, there is a foreign language which uses the Latin alphabet, but the order among the letters is not ABC all the way to Z, we don't know what the order is and that is what we have to figure out. Basically, if we receive an input like this, then we know that H comes before E, yeah. Um, We also know that like E comes before R and we can kind of derive all of these relationships from looking at the order of the words that we get here. And so we need to return a valid ordering. This problem I think is hard because it has many parts. And so this first part is actually going to be deriving how we figure out the relationships between these letters. And then from there, part two will be about putting them in the right order. So as I'm talking this out, I'm actually going to write down this steps of what I'm doing and that will then become our algorithm that we can translate into code later. And it's interesting because like we don't really get any information from looking at any of these words alone. The magic happens when you look at the words in pairs. So I'm going to compare pairs of words. That's where I'm actually going to start learning something interesting here. So I'm going to just start looking at the first letter of both of these words and, unluckily, for us they are the same. And so we don't get any information here. So I'm going to write that down. And then if the same move on basically, which is what we're doing here. So these are both H, we don't learn anything. So let's just actually look next. Okay, and so these are both R, well, we're kind of in the same situation as we were before. So let's move on. Okay, finally, now we're looking at n versus F here, we finally learn something new. If they're different from each other, we can kind of keep track of this relationship. N comes before F in this alien alphabet. I'm going to represent that like this. We reached the end of these words. So let's move on to our next pair. So we already immediately start comparing letter by letter and we already have learned something interesting. We've learned that H comes before E in this alphabet. I'm going to store that relationship as well. Okay, so here's our next pair. These two E are the same, so we don't learn anything, but we learned that R comes before N in this. Okay. And that's really the only relationship I can extract from this pair. Okay. So in this example, we actually learned that E comes before R. If you've been following me, you know that I have been teaching graphs lately and interestingly here, a graph represents relationships between objects via nodes and edges. And curiously, what did we just derive? We just derived a bunch of relationships. And so, I fear that this is a . So let's actually just draw the graph that we have derived here. The nodes are going to be these letters and the edges are going to be these relationships. This actually reduces to another problem that I recently solved. I've actually made two videos about this problem. So if you know what problem this reduces to, leave me a comment and I will be very impressed. Okay, I feel this video has gotten way too long and so the next part will actually show the code and as always thanks for learning along with me.