1.

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

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.



Discussion

No Comment Found

Related InterviewSolutions