Social Network Analysis Functions

Verified

Added on  2019/09/18

|2
|711
|128
Homework Assignment
AI Summary
This assignment focuses on implementing several Python functions to analyze a social network represented as a dictionary and a set of pairs. The functions include `by_n_friends` to group people by their number of friends, `suggestions` to find potential new friendships, `clique` to check if a group is a clique, `most_commons` to find the pair with the most mutual friends, `strangers` to check for complete strangers in a group, `is_cover` to check if a group covers the network, `triangles` to count triangles, and `minimal_cover` to find the smallest covering set. The provided code includes the network data and the function descriptions.
Document Page
pairs = {("Ana", "Berta"), ("Ana", "Greta"), ("Ana", "Helga"),
("Berta", "Cilka"), ("Berta", "Helga"),
("Cilka", "Dani"),
("Dani", "Ema"), ("Dani", "Greta"), ("Dani", "Helga"),
("Ema", "Fanči"), ("Ema", "Greta"), ("Ema", "Helga"),
("Fanči", "Iva"), ("Fanči", "Jana"), ("Fanči", "Klavdija"),
("Greta", "Helga")}
For simplicity and efficiency, every pair is listed just once, in alphabetic order (e.g. ("Ana",
"Berta") and not also ("Berta", "Ana").
The other representation is a dictionary, where keys contain names and the corresponding
values are sets of friends.
network = {"Ana": {"Berta", "Greta", "Helga"},
"Berta": {"Ana", "Helga", "Cilka"},
"Cilka": {"Berta", "Dani"},
"Dani": {"Cilka", "Ema", "Greta", "Helga"},
"Ema": {"Dani", "Fanči", "Greta", "Helga"},
"Fanči": {"Ema", "Iva", "Jana", "Klavdija"},
"Greta": {"Ana", "Dani", "Ema", "Helga"},
"Helga": {"Ana", "Berta", "Dani", "Ema", "Greta"},
"Iva": {"Fanči"},
"Jana": {"Fanči"},
"Klavdija": {"Fanči"}
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Write following functions.
by_n_friends(network) returns a dictionary with keys from 1 to len(mreza) - 1 and
the corresponding sets of people with that number of friends. For instance, for the
small network, the function must return {1: {"D"}, 2: {"A", "B"}, 3: {"C"}}. See the
example for the large network in the tests.
suggestions(network) returns a list of pairs that are not friends but have at least one
common friend. The pair must be sorted alphabetically (e.g. ("Ana", "Berta") and not
("Berta", "Ana")).
clique(network, names) returns True if all persons from the group names know each
other, and False otherwise.
most_commons(network) returns the pair with the most mutual friends.
strangers(network, names) returns True if the group names contains absolute
strangers - not even one pair knows each other -, and False otherwise.
is_cover(network, names) returns True if the group "covers" the entire network in
the sense that every person in the network is either in the group or is a friend with
someone in the group.
triangles(network) computes the number of "triangles" - triplets of people who know
each other.
minimal_cover(mreza) returns the smallest set of names that cover the network (in
the sense described at function is_cover, above).
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]