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
If you have a windows 8, but want the features of windows 8 pro, purchase and install _______.
Xelga [282]
You should just use the windows 8 upgrade, that should work.
3 0
3 years ago
Michael is stuck due to an electric shock generated at the fridge. What should you do to save michael?.
NISA [10]

Pull him away from the fridge with a non-conducting material and begin cardiopulmonary resuscitation .

<h3>What is meant by electric shock?</h3>

When a human comes into contact with an electrical energy source, they experience an electric shock. A shock is produced when electrical energy passes through a section of the body. Exposure to electrical energy has the potential to cause fatalities or absolutely no injuries.

The tangible and tangible result of an electrical current entering the body is electrical shock. The shock could be anything from a dangerous discharge from a power line to an uncomfortable but safe jolt of static electricity after walking over a thick carpet on a dry day. trauma; related topics.

The complete question is : Michael is stuck due to an electric shock generated at the fridge. What should you do to save Michael?

A. push the fridge away with a non-conducting material and begin cardiopulmonary resuscitation

B. push the fridge away from him and begin cardiopulmonary resuscitation

C. pull him away from the fridge with a non-conducting material and begin cardiopulmonary resuscitation

D .pull him away from the fridge with your hands and begin cardiopulmonary resuscitation

To learn more about electric shock refer to:

brainly.com/question/28361869

#SPJ1

7 0
1 year ago
Why is the binary number system used in digital logic?
Slav-nsk [51]
<span>Binary number system used in digital logic because of the simplest nature of its representation.</span>
8 0
3 years ago
Based on the pedigree chart what should you assume about the perental generation
koban [17]

Answer:

The mother was a carrier for a sex-linked disease.

Explanation:

6 0
3 years ago
Software that manages and supports the resources of a computer is known as?
irakobra [83]
The answer to this question is

<span>Systems software are programs that manage the resources of the computer system and simplify applications programming. They include software such as the operating system, database management systems, networking software, translators, and software utilities.


If you taken a computer course, it tells you this information.

Hope This Helps!
:D
</span>
3 0
3 years ago
Other questions:
  • Hiding an object, such as a diary, to prevent others from finding it is an example of:______________.
    10·1 answer
  • Although highly accurate navigational information from the GPS constellation is exploitable by adversary forces, it is unlikely
    5·1 answer
  • List &amp; briefly explain 5 benefits of having a Business bank account.
    9·2 answers
  • I don't understand how to write code for this in Java using nested for loops only. The official question is: write a program tha
    8·1 answer
  • What is obtained after processing data?​
    8·1 answer
  • What is better apple or andriod
    11·2 answers
  • Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the
    15·1 answer
  • Please help! In your own words explain the difference between a problem and an algorithm.
    13·2 answers
  • Tip of advice on brainliest.You can copy and paste the question then search it in the search bar because i can guaranty that som
    14·1 answer
  • What are the task performed by window media player<br> ​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!