Question: So Im supposed to write Python code that implements the Horspool matching algorithm for finding a pattern in a text. We are supposed to add

So Im supposed to write Python code that implements the Horspool matching algorithm for finding a pattern in a text. We are supposed to add counters counting only key comparisons but not counting anything in the creation of the shift table. The def HorspoolMatching(pattern,text): function should return a list. Whose first element is the position of the 1st character of the first match(if no match, return -1) and whose 2nd element is the number of key comparisons. I have written Python code that passes 3 out of 6 tests. Please help fix my code so I also pass test 2,3b, and test 3c.I will put my current code and the test cases that include the correct expected results.
 So Im supposed to write Python code that implements the Horspool
matching algorithm for finding a pattern in a text. We are supposedSo if done correctly and you run def testHorspool() it will print that it passes each test. Please show the output to confirm all 6 tests pass. Test 1,3, and 3a already pass so I think it is a minor problem that Im overlooking. Thanks

RE EB Walcher Mediafools JES Functions Window Layout Help def HorspoolMatching (pattern, text): m len (pattern) n len (text) if m >n: return -1 table= [] for k in range (256): table.append (m) for k in range (m- 1): table [ord (pattern [k])) = m- k- 1 table tuple (table) k=m-1 counter=0 result=[] #to return the final output as firstMatch-0 to check if pattern occurs for the first time while kn: 41 j=m-1; flag=0 to check if comparison happens inside while loop or not while jm 0 and text(i]pattern(31: j 1: i :counter+ 1:flag 1 1 and firstMatch 0: rosult.append (i+1) firstMatch 1 Ichanges the Elag after the first mat k table [ord(text [k]) if flag"#0 and j!--1: when condition fails in line 46 itself but should be included in count counter 1 if len (result) 0: result.append (-1) result.append (counter) return result " def testcaseH (testNumber, string, text, expectedResult) actualResult = Horspoo!Matching (string, text) " if actualResultexpectedResult: print "Test", test Number, "passed." else: print "Test",testNumber, "tailed. Expected", expectedResult, "but found", actualResult

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!