Fixed typos and added a reference. (#27451)
parent
76fd0ce297
commit
87f04caf82
|
@ -2,7 +2,7 @@
|
|||
title: Graphs
|
||||
---
|
||||
## Graphs
|
||||
A graph is a data-structure you can use to solve routing problems, such as "Are these two components connected?" and "What is the shortest path from point a to b?"
|
||||
A graph is a data structure you can use to solve routing problems, such as "Are these two components connected?" and "What is the shortest path from point a to point b?"
|
||||
|
||||
A graph consists of nodes and edges.
|
||||
A node (i.e. vertex) is an object in your graph.
|
||||
|
@ -12,22 +12,22 @@ The edge can contain information such as the weight of the edge.
|
|||
If two nodes are connected by an edge, they are neighbours (i.e. adjacent).
|
||||
|
||||
Depending on the problem you can use either two-way (undirected) or one-way (directed) edges.
|
||||
If you have a undirected edge from a to b, there is also a way from b to a.
|
||||
If you have a directed edge from a to b, there is not necessarily an edge from b to a.
|
||||
If you have an undirected edge from a to b, there is also a way from b to a.
|
||||
If you have a directed edge from a to b, there is not necessarily a way from b to a (as this would require a separate directed edge from b to a, which may not exist).
|
||||
|
||||
You can use graphs to formulate situations such as:
|
||||
* Geographical maps
|
||||
* Each city in your country is a node
|
||||
* If two cities are connected by a road there is a edge between them
|
||||
* If two cities are connected by a road there is an edge between them
|
||||
* Roads can be one- or two-way (both directed and undirected edges)
|
||||
* the weight can be the lenght of the road
|
||||
* The weight can be the length of the road
|
||||
* Flow of water
|
||||
* Each floodgate is a node
|
||||
* Each canal is an edge
|
||||
* water will only flow in one direction so the edges are directed
|
||||
* the weight can be the maximum water capacity of the flow
|
||||
* Water will only flow in one direction so the edges are directed
|
||||
* The weight can be the maximum water capacity of the flow
|
||||
|
||||
Example: a graph that has as nodes the capitals of the Nordic countries, and as (undirected) edges the driving distance to cities connected by direct road.
|
||||
Example: a graph that has as nodes the capitals of the Nordic countries, and as (undirected) edges the driving distance to the cities connected by a direct road.
|
||||
```
|
||||
. +---------+
|
||||
. |Reykjavik|
|
||||
|
@ -51,6 +51,8 @@ Example: a graph that has as nodes the capitals of the Nordic countries, and as
|
|||
|
||||
#### More Information:
|
||||
<!-- Please add any articles you think might be helpful to read before writing the article -->
|
||||
[Wikipedia](https://en.wikipedia.org/wiki/Graph_(discrete_mathematics))
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/breadth-first-search/index.md' target='_blank' rel='nofollow'>Breadth First Search (BFS)</a>
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/depth-first-search/index.md' target='_blank' rel='nofollow'>Depth First Search (DFS)</a>
|
||||
|
|
Loading…
Reference in New Issue