Social network: Represents the relationship between users.
Graph theory is a branch of mathematics that studies graphs. In computer science, a graph is a common data structure used to represent the relationship between entities. A graph consists of vertices (nodes) and edges. Vertices represent entities, and edgesEmail List represent the relationship between entities.Adjacency matrix: A two-dimensional array is used to represent a graph.Advantages: The time complexity of determining whether there is an edge between two vertices is O(1).
Disadvantages: The space complexity is high, and it wastes space for sparse graphs.
Adjacency list: A linked list is used to represent a graph.Advantages: Save space, suitable for representing sparse graphs.
Disadvantages: The time complexity of determining whether there is an edge between two vertices is O(V).
Graph traversalDepth-first search (DFS): Start from a vertex and walk along a path to the end. If you reach a dead end, return to the previous node and continue from another branch.
Breadth-first search (BFS): Start from a vertex and visit all its adjacent nodes first, and then visit the adjacent nodes of its adjacent nodes in turn.
Application of graph
https://fgfgh3.wordpress.com/wp-content/uploads/2024/09/fghgfh.jpg?w=407
Social network: Represents the relationship between users.
Transportation network: Represents the roads between cities.
Circuit design: Represents the connection between components in a circuit.
Shortest path problem: Find the shortest path between two points in a graph.
Minimum spanning tree problem: Find an acyclic connected subgraph containing all vertices with the smallest sum of edge weights.
Topological sorting: Linearly sort all vertices in a directed acyclic graph (DAG).
頁:
[1]