Graphs

Python SELF EN
Level 55 , Lesson 0
Available

1.1 Definition of a Graph and its Components

Graph is a data structure consisting of a set of vertices (or nodes) and a set of edges (or arcs) connecting these vertices. Graphs are widely used for modeling and representing various objects and their relationships.

Graph Example

Main Components of a Graph:

Vertices:

  • Elements of a graph representing objects.
  • Denoted as V (set of vertices).
  • For example, V = {A, B, C, D}.

Edges:

  • Connections between vertices representing relationships or links.
  • Denoted as E (set of edges).
  • For example, E = {(A, B), (B, C), (C, D), (A, D)}.
Graph with Labeled Vertices and Edges

Main Characteristics of a Graph:

Degree of a Vertex:

  • The number of edges incident to a given vertex.
  • In an undirected graph, the degree of a vertex is the number of edges connecting it to other vertices.
  • In a directed graph, we distinguish between incoming and outgoing degrees of a vertex.

Path in a Graph:

  • A sequence of edges connecting a sequence of vertices.
  • For example, the path from A to D: A → B → C → D.

Cycle in a Graph:

  • A path that starts and ends at the same vertex.
  • For example, a cycle: A → B → C → A.

1.2 Types of Graphs

Graphs come in various forms, but here are some interesting subtypes:

Types of Graphs

1. Undirected Graph:

The edges of this graph have no direction, meaning the connection between two vertices can be traversed in both directions.

Example:

Social networks where nodes represent people and edges represent their friendships.

2. Directed Graph:

The edges of the graph have direction (usually denoted by arrows), meaning the connection between two vertices can only be traversed in one direction.

Example:

Web page link graphs where nodes are pages and edges are links between them.

3. Weighted Graph:

Edges have weights (numbers) that can represent distances, costs, or other measures.

Example:

Road graphs where nodes are cities and edges are roads with their lengths or travel costs.

4. Mixed Graph:

Contains both directed and undirected edges.

Example:

Transportation systems where some roads are two-way and others are one-way.

5. Planar Graph:

A graph that can be drawn on a plane without its edges crossing.

Example:

Road graphs in a city (without tunnels).

6. Connected Graph:

A graph where there is a path between any pair of vertices.

Example:

A graph representing a city network where each pair of cities is connected by a road.

7. Acyclic Graph:

A graph without cycles.

Example:

A tree representing a file system structure.

1.3 Examples of Graph Applications

1. Social Networks:

  • Nodes represent people, and edges represent friendships between them.
  • Used for analyzing connections, finding communities, user influence, etc.

2. Internet and Routing:

  • Nodes represent routers or computers, and edges represent connections between them.
  • Used for finding optimal data transmission routes.

3. Genomics:

  • Nodes represent genes or proteins, and edges represent interactions between them.
  • Used for analyzing genomic data, finding patterns, etc.

4. Logistics and Transport:

  • Nodes represent cities or transport hubs, and edges represent roads or paths.
  • Used for route optimization, cost minimization, etc.

5. Computer Networks:

  • Nodes represent devices or servers, and edges represent connections between them.
  • Used for designing and managing networks.

6. Data Analysis and Machine Learning:

Graphs are used for representing and analyzing data, finding clusters, creating recommendation systems, and more.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION