• The Amara On Demand team is looking for native speakers of German, Japanese, Korean, Italian, Hindi and Dutch to help with special paid projects
Apply here Hide

## ← shparG gnitrevnI - Intro to Theoretical Computer Science

• 3 Followers
• 13 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=ops74O-RZ2I" data-team="udacity"></div> ``` 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.