Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is Graph | Graphs
Algorithms and Data Structures Overview
course content

Conteúdo do Curso

Algorithms and Data Structures Overview

Algorithms and Data Structures Overview

1. Introduction to ADS
2. List and Array
3. Advanced Data Structures
4. Graphs

bookWhat is Graph

A graph is a mathematical structure consisting of two sets called a set of vertices and a set of edges. The graph is denoted as G(V, E). Of course, vertices in a graph are connected by edges.

The edges and vertices of a graph can represent different entities. For example, in social networks, the vertices of a graph can represent people, and edges can represent relations between those people.

123456789101112131415161718192021222324252627282930
from lolviz import * from IPython.display import display_png graph = graphviz.Digraph() graph.node('Will') graph.node('Sam') graph.node('Mike') graph.node('Jack') graph.node('Diana') graph.node('Nadia') graph.edge('Will', 'Sam', label='follows') graph.edge('Will', 'Mike', label='follows') graph.edge('Will', 'Diana', label='follows') graph.edge('Sam', 'Mike', label='follows') graph.edge('Sam', 'Diana', label='follows') graph.edge('Mike', 'Will', label='follows') graph.edge('Mike', 'Sam', label='follows') graph.edge('Mike', 'Nadia', label='follows') graph.edge('Jack', 'Will', label='follows') graph.edge('Jack', 'Nadia', label='follows') graph.edge('Diana', 'Will', label='follows') graph.edge('Diana', 'Jack', label='follows') graph.edge('Diana', 'Nadia', label='follows') graph.edge('Nadia', 'Diana', label='follows') graph.edge('Nadia', 'Jack', label='follows') graph.edge('Nadia', 'Sam', label='follows') display_png(graph)
copy

On the other hand, the vertices can represent street crossings, and the edges can represent the streets.

12345678910111213141516
from lolviz import * from IPython.display import display_png graph = graphviz.Graph() graph.node('Catalonia Square') graph.node('University Square') graph.node('Spain Square') graph.node('Drassanes Square') graph.edge('Catalonia Square', 'University Square', label='University Roundabout') graph.edge('University Square', 'Spain Square', label='Gran Via de les Corts Catalanes') graph.edge('Spain Square', 'Drassanes Square', label='Parallel Avenue') graph.edge('Drassanes Square', 'Catalonia Square', label='La Rambla') display_png(graph)
copy

Also, we can assign a weight to an edge of a graph that will denote the cost of passing from one vertex to another by this edge.

As you saw above, graphs can be directed and undirected. It depends on the nature of the underlying task and which type of graph we should choose.

What is a graph in the context of graph theory?

What is a graph in the context of graph theory?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 1
some-alt