Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the boyer moore function below Document the running time on a large te

ID: 3605912 • Letter: I

Question

Implement the boyer moore function below

Document the running time on a large text file(document) that is then searched using varying-length patterns

1 def find boyer moore(T, P) 2 Return the lowest index of T at which substring P begins (or else -1).""" 3 ) 4 ifm== 0: return 0 5 last- 6 for k in range(m) n, m = len(T), len(P # introduce convenient notations # trivial search for empty string # build 'last' dictionary last[ P[k] ] k # align end of pattern at index m-1 of text # later occurrence overwrites # an index into T # an index into P 10 11 k=m-1 while i

Explanation / Answer

Running Time Complexity of boyer moore function is O(Length of T * Length of P).

Best case scenario: Length of String P is 0.In this case, Running time complexity will be O(1) because of check on line number 4.
Example:
String T = "Chegg is best platform to learn"
String P = ""
Running Time complexity = O(1)


Secondary Best case scenario: String P exist in the start of String T. In this case, Running time complexity will be O(Length of P).
Example:
String T = "Chegg is best platform to learn"
String P = "Chegg"
Running Time complexity = O(Length of "Chegg") = O(5)

Worst Case Scenario: String P is not present in String T. In this case, whole function will run and return -1. Running time complexity will be O(Length of P * Length of T).

Example:
String T = "Chegg is best platform to learn"
String P = "homework"
Running Time complexity = O(Length of "homework" * Length of "Chegg is best platform to learn") = O(8 * 31)