For two sets ? and ?, their Jaccard similarity, denoted ?(?,?),is defined as
?(?,?) =
|? ∩ ?| |? ∪ ?|
where |?| is the size of set ?; ? ∩ ? is the intersection of ? and?, that is the elements in both of ? and ?; and ? ∪ ? is the unionof ? and ?, that is the elements in at least one of ? and ?. Forexample, if ? = {1,2,3,4} and ? = {2,4,6,8}, then ? ∩ ? = {2,4} and? ∪ ? = {1,2,3,4,6,8} so
?(?,?) =
|? ∩ ?| |? ∪ ?|
=
|{2,4}| |{1,2,3,4,6,8}|
=
2 6
=
1 3
Write a method, jaccard, that given two sets represented asHashSets, returns their Jaccard similarity. The skeleton for themethod is provided in the file Jaccard.java.
The following are a few sample runs:
Input : ? = [1, 2, 3, 4], ? = [2, 4, 6, 8] Return: 0.333333⋯
Input : ? = [\"???â„Ž???\", \"?â„Ž??\", \"????\", \"??????\", \"????â„Ž\"] ? =[\"?â„Ž??\", \"?????\", \"????\", \"??????\", \"????â„Ž\", \"??????\"] Return:0.375
import java.util.*;
public class Jaccard {
  /**
  * Computes the Jaccard similarity of two setsrepresented as HashSets.
  *
  * Time Complexity: O(n) where n is the smaller of thesizes of the two input sets.
  *
  * @param A HashSet representation of one of the twoinput sets
  * @param B HashSet representation of the other of thetwo input sets
  * @return the Jaccard similarity of A and B
  */
  public double jaccard(HashSet A,HashSet B) {
    Â
     //Replace this line with yourreturn statement
     return -1;
  }
}