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

Visualizing a search tree

In the previous chapter, you learned that a graph is a structure in which nodes are connected by edges. A tree is a special type of graph, in which there are no cycles and two nodes are connected by one path. For visualizing trees, we'll use the pydot Python library, which is a Python interface to Graphviz's DOT language. In Chapter 1, Understanding the Depth-First Search Algorithm, we learned that Graphviz is open source graph visualization software, and it provides the DOT language for creating layered drawings of directed graphs. In addition, we'll be using the matplotlib library for displaying the final rendered image.

Now, let's use these libraries to visualize the following simple tree. It has a root node, and three children under the root node:

Figure 5

Consider the following code:

...
import pydot
import matplotlib.image as...
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