
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation of the quickfinduf class, a data structure used to determine if two elements are connected in a graph or an undirected graph. The class includes a constructor, a connected method, and a union method.
Typology: Study notes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

class QuickFindUf { private int[] id;
QuickFindUf(int n) { id=new int[n]; for(int i=0;i<n;i++) id[i]=i; }
public boolean connected(int a,int b) { return (id[a]==id[b]); }
public void union(int a,int b) { int ida=id[a]; int idb=id[b];
int i;
for(i=0;i<id.length;i++) { if(id[i]==ida) id[i]=idb; } } }