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]
3 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]3 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
What is "the last mile of broadband access"? Why is this a problem and what kind of impact does it have on the business world an
zavuch27 [327]

The last mile of broadband access is the last final step of Internet connectivity to the subscriber's home or office.

Explanation:

The last mile of broadband access is the last final step of Internet connectivity to the subscriber's home or office.

Copper wire -

  • popular choice,
  • less durable,
  • offers less bandwidth,
  • prone to interference,
  • cheaper

Alternative is to use Optical fiber connectivity -

  • more durable,
  • offers much higher bandwidth compared to copper wiring,
  • expensive

Business and personal users have to weigh the pros and cons of copper wiring and optical fiber based on above mentioned factors.

Business who can afford the cost can choose Optical Fiber connectivity especially if the business involves working with huge amount of data.

The needs of personal users can be sufficed by copper wiring.

5 0
3 years ago
Prominent is another word for stands out. True False
earnstyle [38]
The answer is TRUE.

There you go.
6 0
3 years ago
STEAM game launcher question.
son4ous [18]

Answer:

Try to look up csgo map maker and you might be able to transfer the file

Explanation:

4 0
3 years ago
Class 10 computer unit 1 all excersise​
kenny6666 [7]
Y’all just asking for people do your work, literally not even a question
5 0
3 years ago
Write a function listLengthOfAllWords which takes in an array of words (strings), and returns an array of numbers representing t
vesna_86 [32]

Answer:

   public static int[] listLengthOfAllWords(String [] wordArray){

       int[] intArray = new int[wordArray.length];

       for (int i=0; i<intArray.length; i++){

           int lenOfWord = wordArray[i].length();

           intArray[i]=lenOfWord;

       }

       return intArray;

   }

Explanation:

  1. Declare the method to return an array of ints and accept an array of string as a parameter
  2. within the method declare an array of integers with same length as the string array received as a parameter.
  3. Iterate using for loop over the array of string and extract the length of each word using this statement  int lenOfWord = wordArray[i].length();
  4. Assign the length of each word in the String array to the new Integer array with this statement intArray[i]=lenOfWord;
  5. Return the Integer Array

A Complete Java program with a call to the method is given below

<em>import java.util.Arrays;</em>

<em>import java.util.Scanner;</em>

<em>public class ANot {</em>

<em>    public static void main(String[] args) {</em>

<em>       String []wordArray = {"John", "James", "David", "Peter", "Davidson"};</em>

<em>        System.out.println(Arrays.toString(listLengthOfAllWords(wordArray)));</em>

<em>        }</em>

<em>    public static int[] listLengthOfAllWords(String [] wordArray){</em>

<em>        int[] intArray = new int[wordArray.length];</em>

<em>        for (int i=0; i<wordArray.length; i++){</em>

<em>            int lenOfWord = wordArray[i].length();</em>

<em>            intArray[i]=lenOfWord;</em>

<em>        }</em>

<em>        return intArray;</em>

<em>    }</em>

<em>}</em>

This program gives the following array as output: [4, 5, 5, 5, 8]

7 0
3 years ago
Other questions:
  • Face book requires you to change your password regularly<br> a. TRUE<br> b. FALSE
    14·1 answer
  • ON QUIZ PLEASE HELP
    13·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an <br> ___?
    14·1 answer
  • HELP
    11·1 answer
  • Do you think it’s better for a young designer to use free, open-source art programs or to pay for commercial programs? Explain y
    14·1 answer
  • Which of the following statement is correct ? A . potential difference is measured by ammeter . B . The unit of potential differ
    9·1 answer
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
  • What are the common camera hazards? When might you encounter these hazards in your life, and what do you plan to
    14·1 answer
  • What approach do you prefer to take when creating presentations for class projects? Would you rather use software or create pres
    12·2 answers
  • Many people are scared of the rise of Artificial Intelligence (AI). Do you think computers that are controlled by an AI are some
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!