Question

In: Computer Science

Analyze the algorithm experimentally. a)Implement the algorithm b)Let p be the string length at which your...

Analyze the algorithm experimentally.
a)Implement the algorithm
b)Let p be the string length at which your program takes 2 seconds to run, collect running times for your algorithm using the following string lengths: p/4, 2p/4, 3p/4, p, 5p/4, 6p/4, 7p/4, 2p.
c)Generate your strings by reading the attached file, only reading as many characters as you need.
d)Plot your results (x-axis is string length, y-axis should be time)
e)Draw conclusions based on your graph. You may also need to plot another curve (e.g., length(y), length(y)2, or length(y)3, to support your conclusions).

Solutions

Expert Solution

Answer: For Implementing this Algorithm we have taken the function which accepts the string when calling and then plotting the graph as string of length p takes 2 seconds to run.

Here is the code for the following algorithm:

import matplotlib.pyplot as plt
%matplotlib inline
def st(p):
    num=len(p)
    x=[]
    y=[]
    for i in range(1,9):
        x.append(i*num/4)
    for j in x:
        y.append(2*j)
    #print(x)
    #print(y)
    plt.plot(x,y)
    plt.xlabel("Length of String")
    plt.ylabel("Time Taken")
    plt.title('Comparisons')
    plt.show()

st("Hi")
st("We are Using python")
st("Have a Happy Coding!!")

Now is some glimpse of the Output Obtained:

From the Output of the Algorithm We came to know that there is linear growth of algorithm with time.

Have a Happy Coding!!


Related Solutions

A taut string of density p and length b is fixed at both ends. At a...
A taut string of density p and length b is fixed at both ends. At a distance 3b/7 from the origin it is pulled up by an amount h, and at a distance 4b/7 it is pulled down by the same amount. Both points are released simultaneously. Describe the motion and the amplitudes of the normal modes (So, which modes are not excited and why not)
Analyze the motion of a circular pendulum and calculate the length and tension in the string....
Analyze the motion of a circular pendulum and calculate the length and tension in the string. Assume the mass of the pendulum bob is 0.5 kg. the period of the pendulum is 1.19 s. and the radius of the circle is 20 cm, determine the approximate radius of the circle the pendulum sweeps out. Perform a force analysis on the pendulum bob. What is the tension in the string?
Let A and B be two events in a sample with P(A)=0.4 and P(AuB)=0.7.Let P(B)=p a)i...
Let A and B be two events in a sample with P(A)=0.4 and P(AuB)=0.7.Let P(B)=p a)i For what value of p are A and B mutually exclusive? ii for what value of p are A and B independent? b) Assume that P(A)=0.4 and P(B)=0.3 i find P(B') ii if A and B are mutually exclusive , what is P(A or B) ii given that P(A or B)=0.6, Find the P(B/A) c) suppose events A and B are such that P(A)=0.25,P(B)...
Which of this method of class String is used to obtain a length of String object?...
Which of this method of class String is used to obtain a length of String object? What is the output of the below Java program with WHILE, BREAK and CONTINUE? int cnt=0; while(true) { if(cnt > 4)    break;    if(cnt==0) {     cnt++; continue; }   System.out.print(cnt + ",");   cnt++; } 1,2,3,4 Compiler error 0,1,2,3,4, 1,2,3,4,
use ELGMAL algorithm. let p = 11. find a generator number for p in case of...
use ELGMAL algorithm. let p = 11. find a generator number for p in case of elgmal algorithm. alice selects an integer number x = 5. calculate public and private key for alice in elgmal algorithm. alice wants to send plaintext "AGE" to Bob. assume that Alice selects random k values as 6, 4, 7 respectively for encryption. what is the ciphertext???
Let P ( A ) = 0.5, P ( A ∩ B ) = 0.2 and...
Let P ( A ) = 0.5, P ( A ∩ B ) = 0.2 and P ( A | B ) = 0.5. Determine P ( B ) =  (as a decimal) and P ( A ∪ B ) =  (as a decimal) Three identical light bulbs are connect in parallel. If the probability of the system to operate normally is 99.2%, determine the probability of each light bulb to fail p =  (as a decimal).
Let A be an integer array of length n. Design a divide and conquer algorithm (description...
Let A be an integer array of length n. Design a divide and conquer algorithm (description and pseudo code) to find the index of an element of the minimum value in the array. If there are several such elements, your algorithm must return the index of the rightmost element. For instance, if A = {0,2,4,5,2,0,3,10}, then the algorithm should return 5, which is the index of the second 0.
Let P(A) = 0.40, P(B) = 0.20, P(C) = 0.50, P(D) = 0.30, P(A ∩ B)...
Let P(A) = 0.40, P(B) = 0.20, P(C) = 0.50, P(D) = 0.30, P(A ∩ B) = 0.15, P(A | C) = 0.60, P(B | C) = 0.20, P(B ∩ D) = 0.10, and C and D are mutually exclusive. Find ... a. P(C ∩ D) b. P(C U D) c. P(B ∩ C) d. Which one of the following pairs is a pair of statistically independent events? (A and C) (B and D) (B and C) (C and D)
Let A and B be events with P(A) = 0.5, P(Bc ) = 0.4, P(Ac ∩...
Let A and B be events with P(A) = 0.5, P(Bc ) = 0.4, P(Ac ∩ Bc ) = 0.3. (a) Calculate P(A ∪ B), P(A ∩ B), P(B|(A ∪ B)), and P(Ac |B). b) Are A and B independent? Explain why.
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT