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
lesya692 [45]
4 years ago
10

Write a program that prompts the user to enter a string and displays the maximum consecutive increasingly ordered substring. Ana

lyze the time complexity of your program.
Computers and Technology
1 answer:
Marianna [84]4 years ago
7 0

Answer:

a.

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

// Comments marked x represents simple statements

// Comments marked y represents single loop

// Program starts here

import java.util.*;

public class MaxOrder {

public static void main(String args [] ) {

Scanner accept = new Scanner(System.in);

LinkedList<Character> maxtext = new LinkedList<>();

LinkedList<Character> textlist = new LinkedList<>();

System.out.print("Enter a text: ");

String text = accept.nextLine();

// Find the maximum consecutive increasingly ordered substring

for (int i = 0; i < text.length(); i++) { // y1

if (textlist.size() > 1 && text.charAt(i) <= textlist.getLast() && textlist.contains(text.charAt(i))) {

textlist.clear(); // x

}

textlist.add(text.charAt(i)); // x

if (textlist.size() > maxtext.size()) { // x

maxtext.clear();

maxtext.addAll(list);

}

}

// Display the maximum consecutive

// increasingly ordered substring

for (Character ch: maxtext) { // y2

System.out.print(ch); // x

}

System.out.println();

}

b. Analysing the time complexity

In single loop marked y1, there are 3 simple statements ----- 1

In single loop marked y2, there is 1 simple statement --_--- 2

In (1) above,

1 single loop * 3 simple statements = 3;

*

In (2) above,

1 single loop * 1 simple statement = 1;

So, we have

T(n) = O(n) Linear time

You might be interested in
A drowsy cat spots a flowerpot that sails first up and then down past an open window. The pot is in view for a total of 0.50 sec
GaryK [48]

Answer:

2.342m

Explanation:

Given

Time = 0.5 s

Height of Window = 2m

Because the pot was in view for a total of 0.5 seconds, we can assume that it took the cat 0.25 seconds to go from the bottom of the window to the top

Using this equation of motion

S = ut - ½gt²

Where s = 2

u = initial velocity = ?

t = 0.25

g = 9.8

So, we have.

2 = u * 0.25 - ½ * 9.8 * 0.25²

2 = 0.25u - 0.30625

2 + 0.30625 = 0.25u

2.30625 = 0.25u

u = 2.30625/0.25

u = 9.225 m/s ------------ the speed at the bottom of the pot

Using

v² = u² + 2gs to calculate the height above the window

Where v = final velocity = 0

u = 9.225

g = 9.8

S = height above the window

So, we have

0² = 9.225² - 2 * 9.8 * s

0 = 85.100625 - 19.6s

-85.100625 = -19.6s

S = -85.100625/19.6

S = 4.342

If 4.342m is the height above the window and the window is 2m high

Then 4.342 - 2 is the distance above the window

4.342 - 2 = 2.342m

6 0
3 years ago
¿En cuales situaciones concretas se puede aplicar las técnicas de conteo(particularmente las permutuaciones y las combinaciones)
Andrei [34K]

Answer:

In which specific situations can counting techniques (particularly permutuations and combinations) be applied within computer science? for anybody trying to help

7 0
3 years ago
What is Fill handle?
vesna_86 [32]

Answer: I copied and pasted my answer if you need the website to cite information let me know

Explanation:

Fill Handle is a feature in Excel that enables you to auto-complete a list in a row/column by simply dragging it using your mouse. A basic understanding of fill handle in Excel could save you some time and make you more productive.

6 0
3 years ago
I need the answer to life. I cant live without my POGCHAMPS!
Ilya [14]

Answer:

Pray to God and ask him for help in life. May God bless you

Explanation:

8 0
3 years ago
Read 2 more answers
Anyone know this awnser computer science
jolli1 [7]

Answer:

Smartphones, Satellite internet providers, smart speakers, and bluetooth headphones

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Describe the indicators and hazards of a metal deck roof fire in an unprotected steel joist warehouse as well as the techniques
    6·1 answer
  • Which of the following are you likely to find between multiple school buildings in a city wide school district?
    9·1 answer
  • A user has been complaining that their wireless connection has been connecting and disconnecting too frequently. what command co
    15·1 answer
  • A network consists of 10 computers, all running windows 7 professional. one computer acts as a file server and serves up data to
    6·1 answer
  • Select the correct answer.
    10·2 answers
  • We have written a method called sum with an int[] parameter nums. We want our sum method to compute the sum of nums, but our cod
    5·1 answer
  • What do developers do to support software products?
    5·2 answers
  • few toffees were distributed among oriya , piyush and payal . priya got 3/8 , piyush and payal 1/8 and 1/2 of total toffees resp
    5·1 answer
  • When do you use an else statement?
    10·1 answer
  • A(n) ______is like an intranet except it shares its resources with users from a distant location. Select your answer, then click
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!