English subtitles

← shparG gnitrevnI - Intro to Theoretical Computer Science

Get Embed Code
1 Language

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Okay. Let's take a look at my solution. So we defined invert graph.
  2. It takes a graph and then it creates a new graph that we called an inverted graph
  3. that we start as an empty list.
  4. Then for each element in the range of the length of the graph, we append another empty list
  5. to the inverted graph, and we're doing this so we don't change the input graph
  6. in case we still want to use it and since that also wasn't in the problem statement.
  7. Now, for each of those empty list since this is a square matrix,
  8. we again use the length of the input graph.
  9. Now, we check if i is not equal to j that is we're not on the diagonal of the matrix,
  10. and if so, we append 1- the current value.
  11. So basically, we flip that from 1-0, from 0-1.
  12. If we are on the diagonal, then we just put 0 there since we have already specified
  13. that we're not allowing loops and once we get done with this, we simply return the inverted graph.