The Hausdorff distance between two sets of points A and B corresponds to the largest of the distances between each object x ϵ A and its nearest neighbor in B. The Hausdorff distance has several applications, such as comparing medical images or comparing two transport routes. There are different algorithms to compute the Hausdorff distance, some operate with the sets of points in main memory and others in secondary memory. On the other hand, to face the challenge of indexing large sets of points in main memory, there are compact data structures such as k2-Tree which, by minimizing storage, can be efficiently consulted. An efficient algorithm (HDK2) that allows the calculation of the Hausdorff distance in the compact structure k2-Tree is presented in this article. This algorithm achieves an efficient solution in both time and space. Through a series of experiments, the performance of our algorithm was evaluated together with others proposed in literature under similar conditions. The results allow to conclude that HDK2 has a better performance in runtime than such algorithms.