|
1483 | 1483 | ## Graph Algorithms
|
1484 | 1484 |
|
1485 | 1485 | <details>
|
1486 |
| -<summary>Decomposition of Graphs</summary> |
1487 |
| - |
| 1486 | +<summary>Graphs: Basics</summary> |
| 1487 | + |
| 1488 | +- It's a collection of |
| 1489 | + - **V** **vertices**, and |
| 1490 | + - **E** **edges** |
| 1491 | + - Each edge connects a pair of vertices |
| 1492 | +- A **Loop** connect a vertex to itself |
| 1493 | +- Multiple edges between same vertices |
| 1494 | +- A **Simple** graph |
| 1495 | + - It's a graph |
| 1496 | + - It doesn't have loops |
| 1497 | + - It doesn't have multiple edges between same vertices |
| 1498 | +- The **degree** a vertex: |
| 1499 | + - It's also called **valency** of a vertex |
| 1500 | + - It's the number of edges that are incident to the vertex |
1488 | 1501 | - Implementation, Time Complexity and Operations:
|
1489 |
| - |
| 1502 | + - **Edge List**: |
| 1503 | + - It consists of storing the graph as a list of edges |
| 1504 | + - Each edge is a pair of vertices, |
| 1505 | + - E.g., Edges List: (A, B) --> (A, C ) --> (A, D) --> (C , D) |
| 1506 | + - **Adjacency Matrix**: |
| 1507 | + - Matrix[i,j] = 1 if there is an edge, 0 if there is not |
| 1508 | + - E.g. |
| 1509 | + A B C D |
| 1510 | + A 0 1 1 1 |
| 1511 | + B 1 0 0 0 |
| 1512 | + C 1 0 0 1 |
| 1513 | + D 1 0 1 0 |
| 1514 | + - **Adjacency List**: |
| 1515 | + - Each vertex keeps a list of adjacent vertices (neighbors) |
| 1516 | + - E.g. |
| 1517 | + Vertices: Neighbors |
| 1518 | + A B -> C -> D |
| 1519 | + B A |
| 1520 | + C A -> D |
| 1521 | + D A -> C |
| 1522 | + - Time Complexity Edge List Adjacency Matrix Adjacency List |
| 1523 | + IsEdge(v1, v2): O(|E|) O(1) O(deg) |
| 1524 | + ListAllEdge: O(|E|) O(|V|^2) O(|E|) |
| 1525 | + ListNeighbors(v): O(|E|) O(|V|) O(deg) |
| 1526 | +- **Density**: |
| 1527 | + - A **Dense Graph**: |
| 1528 | + - It's a graph where a large fraction of pairs of vertices are connected by edges |
| 1529 | + - |E | ≈ |V|^2 |
| 1530 | + - E.g., Routes between cities: |
| 1531 | + - It could be represented as a dense graph |
| 1532 | + - There is actually some transportation option that will get you between basically any pair of cities on the map |
| 1533 | + - What matter is not whether or not it's possible to get between 2 cities, but how hard it is to get between these cities |
| 1534 | + - A **Sparse Graph**: |
| 1535 | + - It's a graph where each vertex has only a few edges |
| 1536 | + - |E| ≈ |V| |
| 1537 | + - E.g. 1, we could represent the internet as a sparse graph, |
| 1538 | + - There are billions of web pages on the internet, but any given web page is only gonna have links to a few dozen others |
| 1539 | + - E.g. 2. social networks |
| 1540 | + - **Asymptotique analysis depends on the Density of the graph** |
1490 | 1541 | - Programming Languages:
|
1491 | 1542 | - Python:
|
1492 | 1543 | - C++:
|
1493 | 1544 | - Java:
|
1494 | 1545 | - Related Problems:
|
1495 | 1546 | -
|
1496 |
| -- Use Cases: |
1497 |
| - - |
1498 | 1547 | - For more details:
|
1499 |
| - - UC San Diego Course:[]() |
| 1548 | + - UC San Diego Course:[Basics](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/blob/master/3-graph-algorithms/1_graph_decomposition/09_graph_decomposition_1_basics.pdf) |
| 1549 | + - UC San Diego Course:[Representation](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/blob/master/3-graph-algorithms/1_graph_decomposition/09_graph_decomposition_2_representations.pdf) |
| 1550 | + - Khanacademy [Introduction to Graphs](https://www.khanacademy.org/computing/computer-science/algorithms/graph-representation/a/describing-graphs) |
| 1551 | + |
| 1552 | +</details> |
| 1553 | + |
| 1554 | +<details> |
| 1555 | +<summary>Graphs: Exploring</summary> |
| 1556 | + |
| 1557 | +- For more details: |
| 1558 | + - UC San Diego Course:[Exploring Graphs](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/blob/master/3-graph-algorithms/1_graph_decomposition/09_graph_decomposition_3_explore.pdf) |
1500 | 1559 |
|
1501 | 1560 | </details>
|
1502 | 1561 |
|
|
1535 | 1594 | - UC San Diego Course:[]()
|
1536 | 1595 |
|
1537 | 1596 | </details>
|
| 1597 | + |
1538 | 1598 | ---
|
1539 | 1599 |
|
1540 | 1600 | ## NP-Complete Problem
|
|
0 commit comments