Using the string-matching algorithm, write all the comparisons executed with the following text and pattern: text 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 pattern 1 1 1 How many character comparisons were executed by the string-matching algorithm in the exercise above?
Added by Steven L.
Close
Step 1
In a brute-force algorithm, we compare each character of the text with each character of the pattern until we find a match or reach the end of the text. Given the text "text" and the pattern "pattern", let's go through the comparisons: Show more…
Show all steps
Your feedback will help us improve your experience
Crystal Wang and 71 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Determine a big- $O$ estimate of the number of character comparisons used by the naive string matcher to find all occurrences of a pattern of $m$ characters in a text with $n$ characters, in terms of the parameters $m$ and $n .$
Algorithms
Complexity of Algorithms
Design an algorithm that, given two strings of characters, tests whether the second string is same as the first string or not.
'Write an algorithm in pseudocode to count the number of capital letters in a file of text How many comparisons does it do? What is fewest number of increments it might do? What is the largest number? Assume that N is number of characters in a file.'
Samuel G.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD