If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Using matrices to represent data: Networks

Matrices are basically tables of numeric values. But you may be surprised at how many real-world situations you can model with this structure. Here, for example, we represent a network of bus routes between cities. Created by Sal Khan.

Want to join the conversation?

  • winston default style avatar for user Paul
    I know its not the point, but what a terrible design, you end up with a load of buses in city 2 you don't need
    (10 votes)
    Default Khan Academy avatar avatar for user
    • duskpin ultimate style avatar for user TotallyNotAFurryÒwÓ
      You're right, the design could be improved to minimize the number of unnecessary buses in City 2. One possible solution could be to implement a more flexible system, where buses are dynamically allocated based on demand. For example, buses could be dispatched from City 1 to City 2 only when there are enough passengers to justify the trip. Alternatively, the system could use smaller, more efficient vehicles that are better suited to the expected passenger load, which would help to reduce waste and improve overall efficiency. Ultimately, the best design will depend on the specific needs and constraints of the system, as well as the available technology and resources.
      (3 votes)
  • aqualine ultimate style avatar for user Simum
    What is a node?
    (3 votes)
  • blobby green style avatar for user adminravi
    First decide, it's train or bus?
    (4 votes)
    Default Khan Academy avatar avatar for user
  • sneak peak green style avatar for user aungpaingsoe1243
    Is matrix the same idea as two-way table?
    It looks like two-way table to me.
    (2 votes)
    Default Khan Academy avatar avatar for user
  • male robot hal style avatar for user KEVIN
    True? If we start at City 1, we can get back to City 1 via the arrows that go from City 1 to City 3, to City 2, back to City 1. I think the rules/conditions for how we can move. or not move, from City to City need some explanation. In other words, when Sal uses "direct", does that explicitly mean only from one node (City) to another? If someone has a different take on this, please let me know. Always appreciated.
    (3 votes)
    Default Khan Academy avatar avatar for user
  • duskpin ultimate style avatar for user Lydia
    Now, this is cool and all, but would anyone actually use matrices like this in real life? If so, plz tell me how/when.
    If not, plz can someone tell me what other things matrices are useful for in real life?
    Thanks in advance!
    (1 vote)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user nait
      Matrics (from what I know) are used to plot graphs and statistics but can also represent data in the real world like population, fertility rates and more. There are many uses to matrics and it can vary throughout different fields so if these aren't enough examples, I suggest looking up its uses within different working environments/fields
      (4 votes)
  • piceratops tree style avatar for user John
    Why does the question say train routes, then changes to bus routes. -- The network diagram represents the different train routes between three cities. Each node is a city and each directed arrow represents a direct bus route from city to city.
    (1 vote)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Aubrey Lastrella
    I don't get how Sal knows which column and row that indicates which is incoming and outgoing
    (1 vote)
    Default Khan Academy avatar avatar for user
  • starky sapling style avatar for user Nicula.Purity
    How difficult would you say it is to understand
    (1 vote)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user shukranissimo
    i was wondering if it makes sense if, for the scenario where you start at City1 and end at City2:
    - take one of the arrows that go to City3 and then one extra arrow from City3 to City2. In that case, wouldn't it be 4 + 1 (that that goes from City3 to City2)?
    (1 vote)
    Default Khan Academy avatar avatar for user

Video transcript

- [Instructor] We're told this network diagram represents the different train routes between three cities. Each node is a city and each directed arrow represents a direct bus route from city to city. So for example, this arrow right over here, I guess would represent a direct bus route that starts in city three and ends in city one, while this arrow that has an arrow on both sides shows a route that both starts in city three and ends in city one, and a route that starts in city one and ends in city three. So it says, complete the matrix so it represents the number of direct routes between the cities, where rows are starting points and columns are end points. So this is the matrix right over here. I encourage you if you feel so inspired, and I encourage you to feel so inspired, pause this video and see if you can fill out this matrix right over here. You have nine entries in this matrix for each of these combinations between the starting city and ending city. All right, now let's do it together. So, what would go here? This would be the number of direct routes that start at city one and end at city one. So if we start at city one, are there any things that then end at city one? Well, no. It doesn't look like there's anything that starts at city one and ends at city one. So I'll put a zero there. What about this one right over here? Well it needs to start at city one and end at city two. So let's see. This starts at city one and ends at city two, so that's one. We get two. And then we get three. And then we get four, 'cause you can start at city one here and then end at city two. So we get four. Now how many start at city one and end at city three? Pause this video and think about that, actually. All right, we're gonna start at city one and end at city three. I'm going to get another color out here. So I could start here and go on this route and 'cause this arrow ends at city three, so that's one. This middle one does not start at city one and end at city three. It goes the other way around, so I'm not gonna count that. This one right over here, I can go either way, so I could start at city one and end at city three, 'cause we have that arrow there. And those look like the only two that start at city one and end at city three. So that looks like, go back to the original color, two routes right over there. Now what about starting at city two and ending at city one? Well, if we start at city two and end at city one, these three over here, all of these start at one and end at two. They don't go the other way. But this one on top with the double arrows you can go either way. So you could start at city two and end at city one. So there's one route here. Let's see. Start at city two, end at city two. Well, I don't see anything that looks like that for city two, so this is going to be a zero. And then starts at city two, ends at city three. So starts at city two, ends at city three. This arrow doesn't count, 'cause this starts at three, ends at two, not the other way around. So we get a zero there as well. And then let's go to city three. How many start at three and end at one? So start at three and end at one? So this two-way arrow, you could do that. You could start at three and end at one, so that's one. Then this one right over here starts at three and ends at one because we can see the arrow points to one right over there. And then it looks like, and actually this one, I have so much that I've written here that I actually can't see too well the original. Let me erase it actually, so I can make sure I'm seeing things properly. Yeah, that one, too, looks like, so this one I can do, and then this one I can start at city three and end at city one, as well. So it looks like we have three paths there. Now start at city three, end at city two. That one's a little bit more straight forward. That's that path there, so that is one. And then starts at city three, ends at city three. Well, we have this one right over here. That's the only one, so I would put one. So there you have it. We have filled in this matrix. So which city has the most incoming routes? Pause the video and think about that. So the city with the most incoming routes, we can look at the cities that are the end points, and so city one has a total of zero plus one plus three, has four incoming routes. City two has a total of four plus one, five incoming routes. And city three has a total of two plus zero plus one, has three incoming routes. So it looks like this would be city two with five incoming routes. Which city has the most outgoing routes? Well, then we would just look the other way. Actually, pause the video and think about that. Well, it looks like city one has six outgoing routes. City two only has one outgoing route. I'm just adding up along the row. And city three has, looks like five outgoing routes. So city one was zero plus four plus two. There's a total of six routes that start at city one and go out of the city, so that is city one with six routes.