English

Merging Sorted Lists of Similar Strings

Data Structures and Algorithms 2022-08-22 v1

Abstract

Merging TT sorted, non-redundant lists containing MM elements into a single sorted, non-redundant result of size NM/TN \ge M/T is a classic problem typically solved practically in O(MlogT)O(M \log T) time with a priority-queue data structure the most basic of which is the simple *heap*. We revisit this problem in the situation where the list elements are *strings* and the lists contain many *identical or nearly identical elements*. By keeping simple auxiliary information with each heap node, we devise an O(MlogT+S)O(M \log T+S) worst-case method that performs no more character comparisons than the sum of the lengths of all the strings SS, and another O(Mlog(T/eˉ)+S)O(M \log (T/ \bar e)+S) method that becomes progressively more efficient as a function of the fraction of equal elements eˉ=M/N\bar e = M/N between input lists, reaching linear time when the lists are all identical. The methods perform favorably in practice versus an alternate formulation based on a trie.

Keywords

Cite

@article{arxiv.2208.09351,
  title  = {Merging Sorted Lists of Similar Strings},
  author = {Gene Myers},
  journal= {arXiv preprint arXiv:2208.09351},
  year   = {2022}
}

Comments

13 pages. Associated code at https://github.com/thegenemyers/STRING.HEAP

R2 v1 2026-06-25T01:49:22.705Z