What is the time complexity of the naive pattern matching algorithm in the worst-case scenario?

  • O(m * n)
  • O(m + n)
  • O(n log n)
  • O(n)
The worst-case time complexity of the naive pattern matching algorithm is O(m * n), where 'm' is the length of the pattern and 'n' is the length of the text. This is because, in the worst case, the algorithm may need to compare each character of the pattern with each character of the text.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *