Source code online books for professionals by professionals



Download 4,67 Mb.
Pdf ko'rish
bet26/266
Sana31.12.2021
Hajmi4,67 Mb.
#213682
1   ...   22   23   24   25   26   27   28   29   ...   266
Bog'liq
2 5296731884800181221

Listing 2-4.  A dict with Adjacency Sets
N = {
    'a': set('bcdef'),
    'b': set('ce'),
    'c': set('d'),
    'd': set('e'),
    'e': set('f'),
    'f': set('cgh'),
    'g': set('fh'),
    'h': set('fg')

Note
 

  if you drop the 
set
 constructor in Listing 2-4, you end up with adjacency strings, which would work as well, as 
immutable adjacency lists of characters, with slightly lower overhead. it’s a seemingly silly representation, but as i’ve said 
before, it depends on the rest of your program. Where are you getting the graph data from? is it already in the form of 
text, for example? how are you going to use it?
Adjacency Matrices
The other common form of graph representation is the adjacency matrix. The main difference is the following: Instead 
of listing all neighbors for each node, we have a row (an array) with one position for each possible neighbor (that is, 
one for each node in the graph), and store a value, such as True or False, indicating whether that node is indeed a 
neighbor. Again, the simplest implementation is achieved using nested lists, as shown in Listing 2-5. Note that this
again, requires the nodes to be numbered from 0 to V–1. The truth values used are 1 and 0 (rather than True and 
False), simply to make the matrix more readable.
14
Sets were introduced in Python 2.3, in the form of the sets module. The built-in set type has been available since Python 2.4.
15
This, a dictionary with adjacency lists, is what Guido van Rossum uses in his article “Python Patterns—Implementing Graphs,” 
which is found online at 
https://www.python.org/doc/essays/graphs/
.


Chapter 2 

 the BasiCs
28

Download 4,67 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   266




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
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