NPTEL Social Networks Week 1 And 2 Assignment Answers 2025
1. Which Python code correctly computes the sum of even numbers in the list L = [3, 5, 8, 2, 6]
?
a) sum([x for x in L if x % 2 == 0])
b) sum([x for x in L if x % 2 != 0])
c) sum([x for x in L if x > 2])
d) sum(L)
✅ Answer: a
Explanation: The code filters even numbers (8, 2, 6) and computes their sum.
2. You are given a dictionary d = {'A': 10, 'B': 20, 'C': 30}
. Which Python code snippet correctly adds a new key 'D'
with value 40
to the dictionary?
a) d['D'] = 40
b) d.add('D', 40)
c) d.update('D', 40)
d) d.append({'D': 40})
✅ Answer: a
Explanation: Assigning a new key using square brackets adds a key-value pair to a dictionary.
3. What will be the output of the following code?
pythonCopyEditimport matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y)
plt.show()
a) A bar chart displaying the values in x and y
✅ b) A line graph connecting the points (1,1), (2,4), (3,9), (4,16)
c) A scatter plot with those points
d) A histogram displaying the values
Explanation: plt.plot
by default creates a line graph.
4. Using the NetworkX library, how would you create an undirected graph with three nodes (A
, B
, C
) and two edges (A-B
and B-C
)?
✅ a)
pythonCopyEditG = nx.Graph()
G.add_edges_from([('A', 'B'), ('B', 'C')])
b)
pythonCopyEditG = nx.DiGraph()
G.add_edges_from([('A', 'B'), ('B', 'C')])
c)
pythonCopyEditG = nx.Graph()
G.add_nodes_from(['A', 'B', 'C'])
d)
pythonCopyEditG = nx.Graph()
G.add_edges_from([('A', 'B'), ('B', 'C')], directed=True)
Explanation: nx.Graph()
creates an undirected graph, and add_edges_from
adds the edges.
5. In the PageRank algorithm, what is the primary assumption regarding the link structure of the web?
✅ a) Pages that are linked to more often are likely more important.
b) Pages that are less frequently linked are likely more important.
c) Pages with more content are likely more important.
d) Pages without links are considered equally important.
Explanation: PageRank assigns higher scores to pages that receive more incoming links.
6. In a social network, you are tasked with finding the shortest path between two individuals, A and B. Which of the following algorithms would be most suitable?
a) Dijkstra’s Algorithm
b) A* Search Algorithm
✅ c) Breadth-First Search (BFS)
d) Depth-First Search (DFS)
Explanation: BFS is optimal for unweighted graphs when finding the shortest path.
7. Which of the following methods is commonly used for link prediction in a social network?
a) Collaborative Filtering
b) K-means Clustering
c) Matrix Factorization
✅ d) Jaccard Similarity Index
Explanation: Jaccard Index measures similarity between node neighborhoods.
8. In models of contagion in social networks, what does the term “threshold” specifically refer to?
a) The minimum number of links required to spread an infection
✅ b) The fraction of neighbors a node needs to be influenced by to adopt a new behavior
c) The time it takes for an infection to spread
d) The maximum number of nodes that can be infected
Explanation: Threshold defines adoption criteria in influence models.
9. Which centrality measure would you use to find individuals with the shortest average path length to all others?
a) Degree Centrality
✅ b) Closeness Centrality
c) Betweenness Centrality
d) Eigenvector Centrality
Explanation: Closeness centrality captures how quickly a node can reach others.
10. Which of the following NetworkX functions can be used to predict potential links in a network based on node similarity indices?
✅ a) nx.resource_allocation_index(G)
b) nx.shortest_path_length(G)
c) nx.closeness_centrality(G)
d) nx.betweenness_centrality(G)
Explanation: resource_allocation_index
is used for link prediction.
NPTEL Social Networks Week 2 Assignment Answers
1. A graph has a diameter of 1. Which of the following statements must be true?
a) The graph is a complete graph.
b) All nodes in the graph are directly connected to every other node.
c) The graph contains the maximum possible number of edges for its number of nodes.
d) The graph is sparse with relatively fewer edges compared to nodes.
e) Adding or removing an edge cannot change its diameter.
✅ Answer: a, b, c
Explanation: A diameter of 1 implies that every node is directly connected to every other node, hence it’s a complete graph with maximum possible edges.
2. In the Web Graph model, what do the nodes and edges represent?
a) Nodes are web pages, and edges are hyperlinks between them.
b) Nodes are servers, and edges are data transfer rates.
c) Nodes are users, and edges are user interactions.
d) Nodes are hashtags, and edges are co-occurrence frequencies.
✅ Answer: a
Explanation: The Web Graph represents web pages as nodes and hyperlinks as edges.
3. A dataset represents a multigraph (a graph where multiple edges are allowed between two nodes). Which method in NetworkX allows you to load such a graph from an edge list file?
a) read_multiedgelist()
✅ b) read_edgelist()
with create_using=nx.MultiGraph()
c) read_gml()
d) read_multigraph()
Explanation: To load a multigraph from an edge list, specify create_using=nx.MultiGraph()
.
4. Consider the following GML representation of a directed graph. Which of the following correctly interprets the structure and properties of the graph described by the GML code?
a) Undirected graph with edges (A-B, B-A) with weights 5 and 3.
✅ b) Directed graph: A → B (weight 5), B → A (weight 3)
c) Directed graph: A → B (weight 3), B → A (weight 5)
d) Directed graph with self-loops on A and B
Explanation: Directed edges in GML indicate direction; weights define individual edge attributes.
5. Which of the following statements is true about social network dataset formats?
a) Adjacency Matrix is most efficient for sparse graphs.
b) Edge List format is not ideal for sparse graphs.
✅ c) Adjacency List is space-efficient for sparse graphs and allows fast traversal of neighbors.
d) Gephi File format is not ideal for graphs with edge weights or node attributes.
Explanation: Adjacency lists are preferred for sparse graphs due to space and performance efficiency.
6. Pajek datasets are usually available in which format?
a) .csv
✅ b) .net
c) .txt
d) .tar
Explanation: Pajek graph files use the .net
format.
7. Which NetworkX function would you use to visualize the degree distribution of a graph?
✅ a) nx.degree_histogram(G)
b) nx.closeness_centrality(G)
c) nx.shortest_path_length(G)
d) nx.eigenvector_centrality(G)
Explanation: degree_histogram()
provides the degree distribution data for plotting.
8. In Gephi, which metric would you compute to determine the connectivity between communities in a graph?
✅ a) Modularity
b) Degree centrality
c) Closeness centrality
d) Betweenness centrality
Explanation: Modularity is used to detect community structure in networks.
9. In graph theory, what is the critical threshold for the emergence of a giant connected component in a random graph?
a) When the number of edges equals the number of nodes.
✅ b) When the average degree is 1.
c) When the clustering coefficient reaches 1.
d) When the network diameter becomes constant.
Explanation: A giant component appears when the average degree crosses 1 in random graphs.
10. In a random graph G(n,p), when does a giant connected component typically emerge?
a) When the edge probability p is very small.
✅ b) When the edge probability p is large enough to connect most nodes.
c) When the number of nodes n is very large.
d) When the graph has no isolated nodes.
Explanation: A sufficiently large p ensures connectivity, resulting in a giant component.