Algorithms For Dummies



Download 7,18 Mb.
Pdf ko'rish
bet308/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   304   305   306   307   308   309   310   311   ...   651
Bog'liq
Algorithms

  Reconnecting the Dots 

     175


Creating the graph

To see how traversing a graph might work, you need a graph. The examples in this 

section rely on a common graph so that you can see how the two techniques work. 

The following code shows the adjacency list found at the end of Chapter 8. (You 

can find this code in the 

A4D; 09; Graph Traversing.ipynb

 file on the Dummies 

site as part of the downloadable code; see the Introduction for details.)

graph = {'A': ['B', 'C'],

         'B': ['A', 'C', 'D'],

         'C': ['A', 'B', 'D', 'E'],

         'D': ['B', 'C', 'E', 'F'],

         'E': ['C', 'D', 'F'],

         'F': ['D', 'E']}

The graph features a bidirectional path that goes from A, B, D, and F on one side 

(starting at the root) and A, C, E, and F along the second side (again, starting at 

the root). There are also connections (that act as possible shortcuts) going from B 

to  C,  from  C  to  D,  and  from  D  to  E.  Using  the  NetworkX  package  presented  in 

 Chapter 8 lets you display the adjacency as a picture so that you can see how the 

vertexes and edges appear (see Figure 9-1) by using the following code:

import numpy as np

import networkx as nx

import matplotlib.pyplot as plt

%matplotlib inline

Graph = nx.Graph()

for node in graph:

    Graph.add_nodes_from(node)

    for edge in graph[node]:

        Graph.add_edge(node,edge)

pos = { 'A': [0.00, 0.50], 'B': [0.25, 0.75],

        'C': [0.25, 0.25], 'D': [0.75, 0.75],

        'E': [0.75, 0.25], 'F': [1.00, 0.50]}

nx.draw(Graph, pos, with_labels=True)

nx.draw_networkx(Graph, pos)

plt.show()



176


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   304   305   306   307   308   309   310   311   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish