Question

In: Computer Science

3.       How many successful and unsuccessful comparisons will by made using brute force string matching in a...

3.       How many successful and unsuccessful comparisons will by made using brute force string matching in a binary string of 1000 zeros while trying to match the following patters:

a.       1000

b.       0001

c.       00010

Solutions

Expert Solution

a.) 1000

There will be a total of 1000-4+1 = 997 iterations. In each of these iterations, the first comparison would
itself be unsuccessful. Hence, there will be 997*1 = 997 unsuccessful comparisons and there will not be
any successful comparisons. Total comparisons = 997.

b.) 0001

The Search String (0000….000) is of length 1000; the Search Pattern (0001) is of length 4. Hence, there
will be 1000-4+1 = 997 iterations. In each of these iterations, the first 3 comparisons would be successful
and the last comparison will be unsuccessful. Hence, there will be 997*3 = 2991 successful comparisons
and 997*1 = 997 unsuccessful comparisons. Total comparisons = 2991 + 997 = 3988 comparisons.

c.) 00010

There will be a total of 1000-5+1 = 996 iterations In each of these iterations, the first 3 comparisons would be successful and second last will be unsuccessful .There will be 996*3 = 2988 successful comparisons and 996*1 = 996 unsuccessful comparisons. Total comaprisons = 2988 + 996 = 3984 comparisons.


Related Solutions

Discuss the leadership style that made a team successful or unsuccessful. What was the reason(s) for...
Discuss the leadership style that made a team successful or unsuccessful. What was the reason(s) for the success or failure?
Can all problems in Karp 21 be solved using an Exhaustive search or Brute force? And...
Can all problems in Karp 21 be solved using an Exhaustive search or Brute force? And why
3. How many strings can be made using 9 or more letters of MISSISSIPPI?
3. How many strings can be made using 9 or more letters of MISSISSIPPI?
Do characteristics of identity play a role in how successful/unsuccessful, accepted/rejected leadership ACTIONS are, within a...
Do characteristics of identity play a role in how successful/unsuccessful, accepted/rejected leadership ACTIONS are, within a situational context? Might a theory of adaptive leadership be tied more to participant perceptions of action? Is this a conversation of a more collective/inclusive course-of-action analysis based on how leadership presents itself in context? In lay-terms, is adaptive leadership a theory that says, leadership makes decision in a way that recognizes participant perceptions of leadership based on intersections of identity and the workplace?
Using a UTF-8 Unicode implementation, how many bytes would it require to store the string "Dog!"
Using a UTF-8 Unicode implementation, how many bytes would it require to store the string "Dog!"
How many possible directions are there for the frictional force? Physicists categorize the frictional force according...
How many possible directions are there for the frictional force? Physicists categorize the frictional force according to the relative motion between the two surfaces. What are some of the categories? One category of frictional forces is the static frictional force. What is the relative motion between the surfaces for this category? Describe a theory of static frictional forces. Another category of frictional forces is the kinetic frictional force. What is the relative motion between the surfaces for this category? Describe...
Show how to reduce 3-SAT problem to 3D-Matching problem.
Show how to reduce 3-SAT problem to 3D-Matching problem.
How many character comparisons will the BMH algorithm perform to solve the pattern search problem shown...
How many character comparisons will the BMH algorithm perform to solve the pattern search problem shown below? text: my next door neighbor is a witch pattern: is explain c language
How many: New York license plates can be made that consist of 3 letters followed by...
How many: New York license plates can be made that consist of 3 letters followed by 4 numbers given the restriction that if the first letter is an ‘N’, then the second letter must be a ‘Y’? New York license plates can be made that consist of 3 letters followed by 4 numbers given the restrictions that (1) if the first letter is an ‘N’, then the second letter must be a ‘Y’ and (2) if the second letter is...
Using Python 3 The primary objective of this assignment is to reinforce the concepts of string...
Using Python 3 The primary objective of this assignment is to reinforce the concepts of string processing. Part A: Even or Odd For this first part, write a function that will generate a random number within some range (say, 1 to 50), then prompt the user to answer if the number is even or odd. The user will then input a response and a message will be printed indicated whether it was correct or not. This process should be repeated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT