Assaingment 3 0901CS201007
Assaingment 3 0901CS201007
Assaingment 3 0901CS201007
Q1. Take 10 students from your class and create a friendship network.
Follow the given steps:
1. Initialize an empty graph using NetworkX.
1. Add nodes with IDs as the name of the students.
2. Add edges connecting nodes (students who are friends with each other).
3. Visualize the graph using NetworkX's drawing functions.
4. Determine if the graph is connected.
G = nx.Graph()
students = ['Yashvardhan', 'Aryaman', 'Kartikey', 'Shipra', 'Praveen',
'Yash', 'Prajwal', 'Aditya', 'Sonal', 'Akarshi']
G.add_edge('Yashvardhan', 'Aryaman')
G.add_edge('Yashvardhan', 'Kartikey')
G.add_edge('Yashvardhan', 'Praveen')
G.add_edge('Aryaman', 'Akarshi')
G.add_edge('Aryaman', 'Aditya')
G.add_edge('Praveen', 'Shipra')
G.add_edge('Praveen', 'Prajwal')
G.add_edge('Shipra', 'Sonal')
G.add_edge('Shipra', 'Aditya')
G.add_edge('Aditya', 'Prajwal')
G.add_edge('Kartikey', 'Yash')
G.add_edge('Akarshi', 'Aditya')
nx.draw(G, with_labels = 1)
plt.show()
pos = nx.circular_layout(G)
nx.draw(G, pos, with_labels = 1)
plt.show()
print(nx.is_connected(G))
True
G = nx.Graph()
students = ['Yashvardhan', 'Aryaman', 'Kartikey', 'Shipra', 'Praveen',
'Yash', 'Prajwal', 'Aditya', 'Sonal', 'Akarshi']
nx.draw(G, with_labels = 1)
plt.show()
print(G. number_of_nodes())
10
[843, 756, 355, 235, 777, 364, 493, 597, 177, 598]
10
print (G.edges())
pos = nx.circular_layout(G)
nx.draw(G, pos, with_labels=1)
plt.show()
Number of Nodes: 10
Number of Edges: 15
print(nx.is_connected(G))
True
for i in students:
for j in students:
print (nx.dijkstra_path(G, i, j))
print (nx.dijkstra_path_length(G, i, j))
['Yashvardhan']
0
['Yashvardhan', 'Sonal', 'Kartikey', 'Shipra', 'Aryaman']
1438
['Yashvardhan', 'Sonal', 'Kartikey']
590
['Yashvardhan', 'Sonal', 'Kartikey', 'Shipra']
1083
['Yashvardhan', 'Akarshi', 'Yash', 'Praveen']
1318
['Yashvardhan', 'Akarshi', 'Yash']
541
['Yashvardhan', 'Sonal', 'Kartikey', 'Prajwal']
1083
['Yashvardhan', 'Sonal', 'Kartikey', 'Aditya']
954
['Yashvardhan', 'Sonal']
235
['Yashvardhan', 'Akarshi']
177
['Aryaman', 'Shipra', 'Kartikey', 'Sonal', 'Yashvardhan']
1438
['Aryaman']
0
['Aryaman', 'Shipra', 'Kartikey']
848
['Aryaman', 'Shipra']
355
['Aryaman', 'Shipra', 'Kartikey', 'Praveen']
1625
['Aryaman', 'Shipra', 'Kartikey', 'Sonal', 'Yash']
1567
['Aryaman', 'Shipra', 'Kartikey', 'Prajwal']
1341
['Aryaman', 'Shipra', 'Kartikey', 'Aditya']
1212
['Aryaman', 'Shipra', 'Kartikey', 'Sonal']
1203
['Aryaman', 'Shipra', 'Kartikey', 'Sonal', 'Yashvardhan', 'Akarshi']
1615
['Kartikey', 'Sonal', 'Yashvardhan']
590
['Kartikey', 'Shipra', 'Aryaman']
848
['Kartikey']
0
['Kartikey', 'Shipra']
493
['Kartikey', 'Praveen']
777
['Kartikey', 'Sonal', 'Yash']
719
['Kartikey', 'Prajwal']
493
['Kartikey', 'Aditya']
364
['Kartikey', 'Sonal']
355
['Kartikey', 'Sonal', 'Yashvardhan', 'Akarshi']
767
['Shipra', 'Kartikey', 'Sonal', 'Yashvardhan']
1083
['Shipra', 'Aryaman']
355
['Shipra', 'Kartikey']
493
['Shipra']
0
['Shipra', 'Kartikey', 'Praveen']
1270
['Shipra', 'Kartikey', 'Sonal', 'Yash']
1212
['Shipra', 'Kartikey', 'Prajwal']
986
['Shipra', 'Kartikey', 'Aditya']
857
['Shipra', 'Kartikey', 'Sonal']
848
['Shipra', 'Kartikey', 'Sonal', 'Yashvardhan', 'Akarshi']
1260
['Praveen', 'Yash', 'Akarshi', 'Yashvardhan']
1318
['Praveen', 'Kartikey', 'Shipra', 'Aryaman']
1625
['Praveen', 'Kartikey']
777
['Praveen', 'Kartikey', 'Shipra']
1270
['Praveen']
0
['Praveen', 'Yash']
777
['Praveen', 'Kartikey', 'Prajwal']
1270
['Praveen', 'Aditya']
493
['Praveen', 'Kartikey', 'Sonal']
1132
['Praveen', 'Yash', 'Akarshi']
1141
['Yash', 'Akarshi', 'Yashvardhan']
541
['Yash', 'Sonal', 'Kartikey', 'Shipra', 'Aryaman']
1567
['Yash', 'Sonal', 'Kartikey']
719
['Yash', 'Sonal', 'Kartikey', 'Shipra']
1212
['Yash', 'Praveen']
777
['Yash']
0
['Yash', 'Prajwal']
597
['Yash', 'Aditya']
493
['Yash', 'Sonal']
364
['Yash', 'Akarshi']
364
['Prajwal', 'Kartikey', 'Sonal', 'Yashvardhan']
1083
['Prajwal', 'Kartikey', 'Shipra', 'Aryaman']
1341
['Prajwal', 'Kartikey']
493
['Prajwal', 'Kartikey', 'Shipra']
986
['Prajwal', 'Kartikey', 'Praveen']
1270
['Prajwal', 'Yash']
597
['Prajwal']
0
['Prajwal', 'Kartikey', 'Aditya']
857
['Prajwal', 'Kartikey', 'Sonal']
848
['Prajwal', 'Yash', 'Akarshi']
961
['Aditya', 'Kartikey', 'Sonal', 'Yashvardhan']
954
['Aditya', 'Kartikey', 'Shipra', 'Aryaman']
1212
['Aditya', 'Kartikey']
364
['Aditya', 'Kartikey', 'Shipra']
857
['Aditya', 'Praveen']
493
['Aditya', 'Yash']
493
['Aditya', 'Kartikey', 'Prajwal']
857
['Aditya']
0
['Aditya', 'Kartikey', 'Sonal']
719
['Aditya', 'Akarshi']
843
['Sonal', 'Yashvardhan']
235
['Sonal', 'Kartikey', 'Shipra', 'Aryaman']
1203
['Sonal', 'Kartikey']
355
['Sonal', 'Kartikey', 'Shipra']
848
['Sonal', 'Kartikey', 'Praveen']
1132
['Sonal', 'Yash']
364
['Sonal', 'Kartikey', 'Prajwal']
848
['Sonal', 'Kartikey', 'Aditya']
719
['Sonal']
0
['Sonal', 'Yashvardhan', 'Akarshi']
412
['Akarshi', 'Yashvardhan']
177
['Akarshi', 'Yashvardhan', 'Sonal', 'Kartikey', 'Shipra', 'Aryaman']
1615
['Akarshi', 'Yashvardhan', 'Sonal', 'Kartikey']
767
['Akarshi', 'Yashvardhan', 'Sonal', 'Kartikey', 'Shipra']
1260
['Akarshi', 'Yash', 'Praveen']
1141
['Akarshi', 'Yash']
364
['Akarshi', 'Yash', 'Prajwal']
961
['Akarshi', 'Aditya']
843
['Akarshi', 'Yashvardhan', 'Sonal']
412
['Akarshi']
0