Skip to content

Commit 784023d

Browse files
committed
Tweak graph images and text
1 parent 160522b commit 784023d

File tree

7 files changed

+6
-6
lines changed

7 files changed

+6
-6
lines changed

Graph/Images/DAG.graffle

15 Bytes
Binary file not shown.

Graph/Images/DAG.png

8.15 KB
Loading

Graph/Images/Flights.png

7.1 KB
Loading

Graph/Images/FlightsDirected.png

6.49 KB
Loading

Graph/Images/SocialNetwork.graffle

3 Bytes
Binary file not shown.

Graph/Images/SocialNetwork.png

4.32 KB
Loading

Graph/README.markdown

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ With this hypothetical airline, flying from San Francisco to Moscow is cheapest
2020

2121
Edges can also be *directed*. So far the edges you've seen have been undirected, so if Ada knows Charles, then Charles also knows Ada. A directed edge, on the other hand, implies a one-way relationship. A directed edge from vertex X to vertex Y connects X to Y, but *not* Y to X.
2222

23-
Continuing from the flights example, a directed edge from San Francisco to Juneau in Alaska would indicate that there is a flight from San Francisco to Juneau, but not from Juneau to San Francisco (I suppose that means you're walking back!).
23+
Continuing from the flights example, a directed edge from San Francisco to Juneau in Alaska would indicate that there is a flight from San Francisco to Juneau, but not from Juneau to San Francisco (I suppose that means you're walking back).
2424

2525
![One-way flights](Images/FlightsDirected.png)
2626

@@ -68,15 +68,15 @@ Another common graph that's used by programmers is the state machine, where edge
6868

6969
![State machine](Images/StateMachine.png)
7070

71-
Graphs are awesome. Facebook made a fortune from them. If you're going to learn any data structure, it should be the graph, and the vast collection of standard graph algorithms.
71+
Graphs are awesome. Facebook made a fortune from their social graph. If you're going to learn any data structure, it should be the graph and the vast collection of standard graph algorithms.
7272

7373
## Vertices and edges, oh my!
7474

7575
In theory, a graph is just a bunch of vertex objects and a bunch of edge objects. But how do you describe these in code?
7676

77-
There are two main strategies:
77+
There are two main strategies: adjacency list and adjacency matrix.
7878

79-
**Adjacency List.** In an adjacency list implementation, each vertex stores a list of edges that originate from the vertex. For example, if vertex A has an edge to vertices B, C, and D, then vertex A would have a list containing 3 edges.
79+
**Adjacency List.** In an adjacency list implementation, each vertex stores a list of edges that originate from that vertex. For example, if vertex A has an edge to vertices B, C, and D, then vertex A would have a list containing 3 edges.
8080

8181
![Adjacency list](Images/AdjacencyList.png)
8282

@@ -97,7 +97,7 @@ Let *V* be the number of vertices in the graph, and *E* the number of edges. Th
9797
| Add Edge | O(1) | O(1) |
9898
| Check Adjacency | O(V) | O(1) |
9999

100-
"Checking adjacency" means that we try to determine that a given vertex is an immediate neighbor of another vertex. The time to check adjacency for an adjacency list is **O(V)**, because at worst a vertex is connected to *every* other vertex.
100+
"Checking adjacency" means that we try to determine that a given vertex is an immediate neighbor of another vertex. The time to check adjacency for an adjacency list is **O(V)**, because in the worst case a vertex is connected to *every* other vertex.
101101

102102
In the case of a *sparse* graph, where each vertex is connected to only a handful of other vertices, an adjacency list is the best way to store the edges. If the graph is *dense*, where each vertex is connected to most of the other vertices, then a matrix is preferred.
103103

@@ -185,7 +185,7 @@ v4.connectTo(v1, withWeight: 2.8)
185185
v2.connectTo(v5, withWeight: 3.2)
186186
```
187187

188-
> **Note:** There are many, many ways to implement graphs. The code given here is just one possible implementation. You probably want to tailor the graph code for each individual problem you're trying to solve. For instance, your edges may not need a `weight` property, or you may not have the need to distinguish between directed and undirected edges.
188+
> **Note:** There are many, many ways to implement graphs. The code given here is just one possible implementation. You probably want to tailor the graph code to each individual problem you're trying to solve. For instance, your edges may not need a `weight` property, or you may not have the need to distinguish between directed and undirected edges.
189189

190190
## The code: adjacency matrix
191191

0 commit comments

Comments
 (0)