1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SVEN [57.7K]
3 years ago
7

Determine the number of character comparisons made by the brute-force algorithm in searching for the pattern GANDHI in the text

Computers and Technology
1 answer:
leonid [27]3 years ago
3 0

Answer:

Total number of character comparison = 43

Explanation:

Using the Brute force algorithm

The string of n characters is known as text, and the string of m characters is known as the pattern.

From the given information:

The text (n)=THERE_IS_MORE_TO_LIFE_THAN_INCREASING_ITS_SPEED

The pattern (m) = GANDHI

The total no of characters that we have in the text = 47

The total number of characters in pattern = 6

For a brute force algorithm;

Since; the first character of the pattern does not exist in the text, then the number of trials made can be attempted can be expressed as = n – m + 1

= 47 – 6 + 1

= 47 – 5

= 42

Thus; the algorithm will attempt the trial 42 times.

Now, for loop in the algorithm to run 42 times, the G in the pattern will have to align against the for T in the text, and in the last case, it will be aligned against the last space.

On each attempted trial, the algorithm will make one unsuccessful comparison.

However, at the trial at which the G in the pattern Is aligned with the G in the text, there will be two successful comparisons.

Hence, we can calculate the total number of character comparison as follows:

Total number of character comparison = \mathbf{\bigg ( ( 42 -  (no. \ of \  failed \ comparison) ) \times 1 + (1 \times ( Two \ successful \  comparisons) ) \bigg ) }

Total number of character comparison = ( (( 42 – 1) × 1 ) + ( 1 × 2) )

Total number of character comparison = 41 + 2

Total number of character comparison = 43

You might be interested in
What is the relationship between data, information, business intelligence, and knowledge?
Tpy6a [65]

Answer:

The answer is below

Explanation:

Given the following:

Data is oftentimes described as actual truth or evidence about a situation or condition.

Information, on the other hand, is described as a refined data

Business Intelligence is defined as a combination of several information utilized in the decision-making process.

Knowledge is basically described as a form of intellectual properties, which encompasses a lot of experiences, skills, and creativity.

Therefore, the main relationship between all these is the utilization of these resources to enhance and improve the decision-making process. This is because, the gathered DATA is converted to INFORMATION, which in turn used to build BUSINESS INTELLIGENCE and finally, through the combination of past experiences, skills and talent, leads to a wealth of KNOWLEDGE to enhance and improve the decision-making process.

7 0
3 years ago
Convert the Binary Number to a Decimal Number
Korolek [52]
There are convertors online for this but the answer is 5
<span />
8 0
3 years ago
Which of the following set of instructions defines an algorithm in the formal, strict sense?
Nikolay [14]
Hope that understands

8 0
3 years ago
Write a program to read a sentence which is a single string. Then count the number of words in the sentence. The program will re
patriot [66]

Answer:

The program in Python is as follows:

sentence = input("Sentence: ")

words = len(sentence.split())

print("Words:", words)

Explanation:

This reads the sentence for the user

sentence = input("Sentence: ")

This counts the number of words

words = len(sentence.split())

This prints the number of words

print("Words:", words)

6 0
3 years ago
JAVA CHALLENGE ZYBOOKs
exis [7]

Answer:

Replace  /* Your solution goes here */ with:

<em>System.out.println(randGen.nextInt(49) + 100);</em>

<em>System.out.println(randGen.nextInt(49) + 100);</em>

<em />

Explanation:

Required

Statements to print two random numbers between 100 and 149 (both inclusive)

First, the random numbers must be generated. From the template given, the random object, randGen, has been created.

The syntax to then follow to generate between the interval is:

<em>randGen.nextInt(high-low) + low;</em>

Where:

high = 149 and low = 100

So, the statement becomes:

<em>randGen.nextInt(149 - 100) + 100;</em>

<em>randGen.nextInt(49) + 100;</em>

<em />

Lastly, print the statements:

<em>System.out.println(randGen.nextInt(49) + 100);</em>

<em>System.out.println(randGen.nextInt(49) + 100);</em>

<em />

5 0
3 years ago
Other questions:
  • Which statement correctly explains why televisions became less bulky?
    6·1 answer
  • Mary needs to choose the _____ menu in order to place the text in a desirable fashion around the image
    12·2 answers
  • Assume that the type NAME has already been defined. Define a new type, SREC that is a structure consisting of two fields: name (
    5·1 answer
  • Using the find and replace tool would be most appropriate when
    6·2 answers
  • A0domain indicates that the computer or DNS name does not exist.
    7·1 answer
  • Keyshia adds an image of a triple beam balance and a
    8·1 answer
  • What best describes presentation software?
    14·1 answer
  • Which of the following identifies the goods or services of a
    15·2 answers
  • Original documents or objects used during Internet research are known as
    8·2 answers
  • Assume that you have implemented a sequence class. Describe the mySequence object (i.e., items with the correct order and the po
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!