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
Two of the major sources used today for obtaining information to create computer maps are satellites and _____________.
nikdorinn [45]
The Global Positioning System or GPS.
7 0
3 years ago
Read 2 more answers
TCP will guarantee that your packets will arrive at the destination, as long as the connection is still established. True False
puteri [66]

Answer: True

Explanation: TCP(Transmission control protocol) is the protocol that is responsible for making the connection between the two hosts and then  they can share the data between them.

TCP guarantees that the data or data packets that are being sent from the source will be delivered to the host  in the same way as it was sent from source port. This mechanism ensure that there will be no data manipulation in the order of the data. TCP also has a relation with the IP for the functioning.Thus the given statement is true.

3 0
3 years ago
________ consists of detailed, preprogrammed instructions that control and coordinate the computer hardware components in an inf
Mrrafil [7]

The answer is Software.  It consists of detailed, preprogrammed instructions that control and coordinate the computer hardware components in an information system.  It is a set of instructions and related documentation that tells a computer what to do or how to perform a task or it can mean all the software on a computer, including the applications and the operating system.

5 0
3 years ago
NEED HELP NOW 25 POINTS WILL MARK BRAINLIEST!!!!!!!
Rudiy27
#1, Option D)filters let you filter out certain things or search for them. For example if i'm looking through a database with all the students grades. I could filter out everything that doesnt math a students name. This would only show results for what I searched for.
#2 Option C), filters make it easier to find specific information,
#3 Option A),the unwanted parts of the web are removed from sight!
#4 Option A) you must ad the sort feature first!
Have a splendid day!
6 0
3 years ago
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, g
Lady_Fox [76]

Answer:

Check the explanation

Explanation:

// include the necessary packages

import java.io.*;

import java.util.*;

// Declare a class

public class DataReader

{

// Start the main method.

public static void main(String[] args)

{

// create the object of scanner class.

Scanner scan = new Scanner(System.in);

// Declare variables.

boolean done = false;

boolean done1 = false;

float sum = 0;

double v;

int count = 0;

// start the while loop

while (!done1)

{

// start the do while loop

do

{

// prompt the user to enter the value.

System.out.println("Value:");

// start the try block

try

{

// input number

v = scan.nextDouble();

// calculate the sum

sum = (float) (sum + v);

}

// start the catch block

catch (Exception nfe)

{

// input a character variable(\n)

String ch = scan.nextLine();

// display the statement.

System.out.println(

"Input Error. Try again.");

// count the value.

count++;

break;

}

}

// end do while loop

while (!done);

// Check whether the value of count

// greater than 2 or not.

if (count >= 2)

{

// display the statement on console.

System.out.println("Sum: " + sum);

done1 = true;

}

}

}

}

Sample Output:

Value:

12

Value:

12

Value:

ten

Input Error. Try again.

Value:

5

Value:

nine

Input Error. Try again.

Sum: 29.0

3 0
3 years ago
Read 2 more answers
Other questions:
  • You are using Windows 10 and you have created a file with called “my text” in notepad with a .txt extension type. You need to ch
    13·1 answer
  • Which term describes a protocol to manage a network, able to configure a network, monitor activity, and control devices?
    10·2 answers
  • Why does the job market change overtime
    9·1 answer
  • With ____________________, you can insert and remove a device while the computer is running.
    11·1 answer
  • Applications software is also known as
    14·2 answers
  • Sandra is having difficulty with her reading assignment because she does not fully understand the language. Which online tool wo
    6·1 answer
  • ---------------is a systematic review of a person’swork and achievements over a recent period, usually leading toplans for the f
    11·1 answer
  • What are the words that make up a high-level programming language called?
    6·1 answer
  • Write a program that inputs numbers and keeps a running sum. When the sum is greater than 100, output the sum as well as the cou
    13·1 answer
  • The main function of a(n) ____________________ is to centralize access control for the network by keeping an eye on both inbound
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!