Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Artificial Intelligence for Search

You're reading from   Hands-On Artificial Intelligence for Search Building intelligent applications and perform enterprise searches

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789611151
Length 124 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Devangini Patel Devangini Patel
Author Profile Icon Devangini Patel
Devangini Patel
Arrow right icon
View More author details
Toc

Graph data structure

A graph is a non-linear data structure containing a set of points known as nodes (or vertices) and a set of links known as edges, as illustrated in the following diagram:

Figure 7

An edge that connects to the same node is called a cycle. As shown in the preceding diagram, nodes a and b are connected by two paths; one is through edge a-b, and the other is through edges a-d and d-b. A tree is a special type of graph, in which there are no cycles, and two nodes are connected by one path.

In Python, we can use a dictionary structure to represent a graph. A dictionary is a data structure where many keys are mapped to values. For a dictionary that represents a graph, the keys are the nodes, and the values of those nodes are the nodes that they are connected to:

Figure 8

In the preceding diagram, we can see that the following applies:

  • For key a, the values are...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime