Suppose you have some List of S List of Strings called List and a String prefix. Write a method that removes all the Strings from list that begin with prefix. public void removePrefixStrings(List-String- list, String prefix) 7. What is the time complexity of this algorithm?

Answers

Answer 1

Answer:

public void removePrefixStrings(List<String> list , String prefix) {

if(list==null || list.size()==0)

return;

for(int i=0; i<list.size();) {

if(list.get(i).startsWith(prefix))

list.remove(i);

else

++i;  

}  

}  

Time Complexity: If the prefix is the same as String length, Then finding all prefix match will take n *n = n2

Then removal is also n  

So the total time complexity is O(n3)


Related Questions

Fasilitas untuk pengaturan batas kertas pada Microsoft Word adalah….

a. Margin
b. View
c. LayOut
d. Paragraph

Office 92 sering disebut juga dengan….

a. Office 3.0
b. Office 7.0
c. Office Xp
d. Office 2.0


Answers

Fasilitas untuk pengaturan batas kertas pada Microsoft Word adalah

B.View

Office 92 sering disebut juga dengan

A.Office 3.0

Write a program that asks the user to enter in a username and then examines that username to make sure it complies with the rules above. Here's a sample running of the program - note that you want to keep prompting the user until they supply you with a valid username:

Answers

user_in = input ("Please enter your username: " )

if user_in in "0123456789":

print ("Username cannot contain numbers")

elif user_in in "?":

print ("Username cannot continue special character")

else:

print (" Welcome to your ghetto, {0}! ".format(user_in))

Other Questions
Needed in 2 minutes ASAP A 1.5kg block slides along a frictionless surface at 1.3m/s . A second block, sliding at a faster 4.3m/s , collides with the first from behind and sticks to it. The final velocity of the combined blocks is 2.0m/s . What was the mass of the second block? HELP PLZ!!!!!!!!!!!!!!!!! How does aerobic capacity relate to cardiorespiratory endurance? Consider the reaction: NaNO3(s) + H2SO4(l) NaHSO4(s) + HNO3(g) H = 21.2 kJ How much heat must absorbed by the reaction system to convert 100g of NaNO3 into NaHSO4(s)? The Crusades had which effect on Muslims in Europe?A. Muslims became powerful nobles in European kingdomsB. Muslims were pushed out of many parts of Europe.C. Muslims were killed in pogroms across Europe.D. Most Muslims in Europe became Christian. The Rybczynski theorem asserts that in a two-good world, and assuming that product prices stay constant, growth in the endowment of one factor of production, with the other factor unchanged, will lead to: A. An equal percentage increase in the output of both goods. B. An increase in the output of the good that uses the growing factor intensively and a decrease in the output of the other good. C. An increase in the output of both goods but a greater percentage increase in the output of the good that uses the growing factor intensively. D. An increase in the output of the good that uses the growing factor intensively and no change in the output of the other good. . A ball of mass 0.50 kg is rolling across a table top with a speed of 5.0 m/s. When the ball reaches the edge of the table, it rolls down an incline onto the floor 1.0 meter below (without bouncing). What is the speed of the ball when it reaches the floor? The triangle below is isosceles. Find the length of side x in simplest radical form witha rational denominator.V10Answer: 2==Submit Answer At year-end (December 31), Chan Company estimates its bad debts as 0.30% of its annual credit sales of $896,000. Chan records its Bad Debts Expense for that estimate. On the following February 1, Chan decides that the $448 account of P. Park is uncollectible and writes it off as a bad debt. On June 5, Park unexpectedly pays the amount previously written off. Prepare Chan's journal entries for the transactions. Using your answers from part C, complete the chemical formula of each compound. If the number of ions is 1, leave thatnumber out of the formula.Drag each number to the correct location. Numbers may be used more than once Rotation 90 counterclockwise around the origin of the point (-8,1) Please hurry I will mark you brainliest What is the slope of the line with an x-intercept of 4 and a y-intercept of -3? 1 atm is equal toO 1 mmHg 14.7 mmHg 76 mmHg 760 mmHg Read the following paragraph:"Brownies made from a mix are vastly underrated and can be baked to suit any taste. As with those made from scratch, the texture of browniesfrom a box is dependent on the amount of eggs added to the batter. A single egg produces a denser brownie than one made with two eggs. Brownietexture can also be varied through the choice of pan because glass heats more slowly than metal."Which sentence uses subjective language?O Brownie texture can also be varied through the choice of pan because glass heats more slowly than metal.As with those made from scratch, the texture of brownies from a box is dependent on the amount of eggs added to the batter.O Brownies made from a mix are vastly underrated and can be baked to suit any taste.A single egg produces a denser brownie than two eggs. The assertion that non formal institution have no role to play in the processing stage of the system theory is an empty rhetoric Standish Company manufactures consumer products and provided the following information for the month of February: Units produced 131,000 Standard direct labor hours per unit 0.20 Standard fixed overhead rate (per direct labor hour) $2.50 Budgeted fixed overhead $65,000 Actual fixed overhead costs $68,300 Actual hours worked 26,350Required:a. Calculate the fixed overhead spending variance using the formula approach.b. Calculate the volume variance using the formula approach. hi, please solve these three questions for me, i have to shoe solving steps. PLEASE HELP DUE!!!WILL GIVE BRAINLIEST!!can someone help me please? Devaughn is 6 years older than Sydney. The sum of their ages is 56 . What is Sydney's age?