  We present a fine-grained approach to identify clusters and perform
percolation analysis in a 2D lattice system. In our approach, we develop an
algorithm based on the linked-list data structure whereby the members of a
cluster are nodes of a path. This path is mapped to a linked-list. This
approach facilitates unique cluster labeling in a lattice with a single scan.
We use the algorithm to determine the critical exponent in the quench dynamics
from the Mott insulator to the superfluid phase of bosons in 2D square optical
lattices. The results obtained are consistent with the Kibble-Zurek mechanism.
We also employ the algorithm to compute the correlation length using
definitions based on percolation theory and use it to identify the quantum
critical point of the Bose Glass to superfluid transition in the disordered 2D
square optical lattices. In addition, we compute the critical exponent $\nu$
which quantify the divergence of the correlation length $\xi$ across the phase
transition and the fractal dimension of the hulls of the superfluid clusters.
