data_structures/union-find.py
def union(self, p, q):
        """ Compare the weights of p and q to figure out which tree must be linked to the other """
        pID = self._id(p)
        qID = self._id(q)
        pWeight = self._weight(p)
        qWeight = self._weight(q)

        if pWeight < qWeight:
            self.data[qID][1] = pWeight + qWeight
            self.data[pID][0] = qID
        else:
            self.data[pID][1] = pWeight + qWeight
            self.data[qID][0] = pID
 Compare the weights of p and q to figure out which tree must be linked to the other 
Compare the weights of p and q to figure out which tree must be linked to the other
Compare the weights of p and q to figure out which tree must be linked to the other
def union(self, p, q):
        pID = self._id(p)
        qID = self._id(q)
        pWeight = self._weight(p)
        qWeight = self._weight(q)
        if pWeight < qWeight:
            self.data[qID][1] = pWeight + qWeight
            self.data[pID][0] = qID
        else:
            self.data[pID][1] = pWeight + qWeight
            self.data[qID][0] = pID
def union ( self , p , q ) : pID = self . _id ( p ) qID = self . _id ( q ) pWeight = self . _weight ( p ) qWeight = self . _weight ( q ) if pWeight < qWeight : self . data [ qID ] [ 1 ] = pWeight + qWeight self . data [ pID ] [ 0 ] = qID else : self . data [ pID ] [ 1 ] = pWeight + qWeight self . data [ qID ] [ 0 ] = pID
Compare the weights of p and q to figure out which tree must be linked to the other
Compare the weights of p and q to figure out which tree must be linked to the other
""" Compare the weights of p and q to figure out which tree must be linked to the other """
self
p
q