3 Ways To Represent Graphs in Python | Graph Theory With Python #2

preview_player
Показать описание
In this video, you'll learn three ways to represent graphs in Python: as a tuple, as an adjacency list, and as an adjacency matrix. You'll see how Python's built-in data structures, such as lists and dictionaries, can help you represent graphs in a natural and Pythonic way.

CODE REPOSITORY
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

GRAPH THEORY WITH PYTHON SERIES
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
➢ Part 2: YOU ARE HERE

HELPFUL LINKS
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

SUPPORT ME
¯¯¯¯¯¯¯¯¯¯¯¯¯
My content is, and always will be, completely free. But your support goes a long way to motivate me to continue to produce top-notch math and programming content. You can tip me using any of the following links:

OTHER LINKS
¯¯¯¯¯¯¯¯¯¯¯¯¯¯

#graphdatastructures #pythonprogramming #discretemath #discretemathematics #adjacencymatrix #adjacencylist #adjacencymatric #mathematics #graphtheory
Рекомендации по теме
Комментарии
Автор

The best video I have seen so far on graph representation in Python. Thank you!

emmanuelonah
Автор

Clear voice, good & detailed explanation! This tutorial is a gem!

mahbuburrahmanturzo
Автор

Great video!
Regarding the adjacency matrix: for undirected graphs there is a problem that loops will be recorded twice. For this you should add a condition which checks if node1 == node2.

ScandGeek
Автор

You are the reason I just started fascinating about graph theory ❤

soumya
Автор

Thank you for your smooth explanations.
👌👌

pouyapargam
Автор

Very clear and detailed explanation. Thank you!!

cybercor
Автор

This is a very good presentation, thanks so much.

hericklenin
Автор

Thank you for helping your video sir. Can you send me radio labeling algorithm using python ?

speakbaskar
Автор

def radio_labeling(order, diameter):
labels = [0] * order

# Assign label 1 to vertex 0
labels[0] = 1

# Assign label 2 to the neighbors of vertex 0
for i in range(1, min(diameter + 1, order)):
labels[i] = 2

# Assign labels to the remaining vertices
for i in range(diameter + 1, order):
# Check the labels of neighbors
used_labels = set()
for neighbor in range(i - diameter, i):


# Find the smallest unused label
j = 1
while j in used_labels:
j += 1

# Assign the label to the current vertex
labels[i] = j

return labels

# Example usage
order = 10 # Number of vertices in the graph
diameter = 3 # Diameter of the graph
labels = radio_labeling(order, diameter)
print(labels)

speakbaskar
Автор

This is nice. It's been a while since I've seen graph theory, but I could have sworn the adjacency matrix of a directed graph had negative entries for edges going away from the vertex. Is that just for specific use cases?

InfiniteQuest
Автор

for adjacency list, if we want to add the weight of nodes how can we do that?

hamzashariq
Автор

What a shame there si not a way how to determine, whether we can get somehow through the edges from node x to node y.

andrejznamenacek
Автор

Great work.
How would you extend this concept to graphs in the 3D plain (e.g. a cuboid or 3D Torus) ?
Thanks again.

worldentropy
Автор

If nodes =[1, 2, 3, 4] we will get an index error.
You need to modify the adjacency _matrix function as follow:


To work with node 's index

gradsys
Автор

What if nodes are alphabets like 'A' or 'B'?

jamshaidmushtaq
Автор

Cant wait for the next one. Guess I do a sleep()
Typical mathematican. Keeping track of every click using bitly to analyse later. 😃

sinnvollerkommentar
Автор

for me it says indices must be integers or slice, not list

arnantaroy
Автор

Lord please give me strength so that I can bear this 36 minutes of mental pain

yogeshbhatt