Question: Use python to implement the following function. Suppose we are given a weighted, undirected graph G=(V,E,) in which the edge weights represent similarity; for example,
Use python to implement the following function.

Suppose we are given a weighted, undirected graph G=(V,E,) in which the edge weights represent similarity; for example, the similarity between two users in a social network. Given a number , we will say that the clusters of G are the connected components of the graph after all edges whose weight is less than have been removed. There are other ways of defining the clusters of a weighted graph, but this is one natural way. In cluster.py, write a function cluster (graph, weights, level) which computes the clusters of a weighted graph. Here, graph is an instance of dsc40graph.UndirectedGraph, weights (u, v) is a function returning the weight of edge (u,v), and level is a number representing the level at which to find the clusters. Its return value should be a frozenset 1 containing frozensets; the inner frozensets should contain the nodes in a cluster. Your code should not modify the graph in any way and it should not create a copy of the graph. It should run in (V+E) time. Note that weights is a function that will be constructed by us and passed to your function; you will not need to create it (except in your own tests). For example, given the following graph: The output when run with a level of 0.4 should be: > def weights (x,y) : x,y=(x,y) if x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
