+1 vote
in Data Structures & Algorithms II by (110k points)
What is the time complexity of Z algorithm for pattern searching (m = length of text, n = length of pattern)?

(a) O(n + m)

(b) O(m)

(c) O(n)

(d) O(m * n)

I had been asked this question in a job interview.

My question is from Searching topic in portion Searching of Data Structures & Algorithms II

1 Answer

+1 vote
by (614k points)
selected by
 
Best answer
Correct option is (a) O(n + m)

Explanation: Z algorithm is an efficient pattern searching algorithm as it searches the pattern in linear time. It has a time complexity of O(m + n) where m is the length of text and n is the length of the pattern.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.

Categories

...