What is the best case for a pattern P and string T in string matching?

a. O(n)
b. O(log n)
c. O(m log n)
d. O(n^2)

a. O(n)
O(n) is for the string text T, and a pattern P of one character or O(m) = 1, so for O(n*m) or O(n+m) the time is O(n) or O(n+1) = O(n). Thus, for a single character pattern P on a string text T of length O(n), the best performance is O(n) or linear time.

Computer Science & Information Technology

You might also like to view...

________ data include elements or facts that may or may not have meaning or relevance

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Which of the following statements is true?

a) If the return value of function scanf matches the number of items that should have been input, then all the inputs are valid. b) Even if a scanf operates successfully, the values read might still be invalid. c) When a program expects to receive input values in a specific range, you should peform range checking on the inputs to ensure that the values received are indeed in that range (e.g., in a program that expects grades in the range 0-100, you should check that every grade is in that range). d) Both b) and c).

Computer Science & Information Technology