Skip to content

Commit d7faaa6

Browse files
author
Hamid Gasmi
committed
Graph basics description is added
1 parent 6a17d83 commit d7faaa6

File tree

1 file changed

+66
-6
lines changed

1 file changed

+66
-6
lines changed

README.md

+66-6
Original file line numberDiff line numberDiff line change
@@ -1483,20 +1483,79 @@
14831483
## Graph Algorithms
14841484

14851485
<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
14881501
- 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**
14901541
- Programming Languages:
14911542
- Python:
14921543
- C++:
14931544
- Java:
14941545
- Related Problems:
14951546
-
1496-
- Use Cases:
1497-
-
14981547
- 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)
15001559

15011560
</details>
15021561

@@ -1535,6 +1594,7 @@
15351594
- UC San Diego Course:[]()
15361595

15371596
</details>
1597+
15381598
---
15391599

15401600
## NP-Complete Problem

0 commit comments

Comments
 (0)