This paper presents a modified Needleman-Wunsch algorithm to enhance pairwise sequence alignment between hepatitis B virus (HBV) and hepatocellular carcinoma (HCC) DNA sequences. The proposed method demonstrates a significant reduction in computational time and space complexity while achieving high similarity rates of approximately 96.55% and validity of 99.85% across 10,296 alignments. The study indicates that the modification allows for effective alignment while addressing the high complexity of traditional algorithms.