Question

Answer B

javaProblem 2 For each problem given below, do the following: 1. Create an algorithm in pseudocode to solve the problem. 2.Identify the factors that would influence the running time of your algorithm. For example, if your algorithm is to search an array the factor that influences the running time is the array size. Assign names (such as n) to each factor. 3. Determine the number of operations in each step of the pseudocode. To do that, identify the operations that must be counted. You need not count every statement separately. If a group of statements always executes together, treat the group as a single unit. If a method is called, and you do not know the running time of that method count it as a single operation 4. Count the operations performed by the algorithm. Express the count as a function of the factors you identified in Step 2. 5. Describe the best case scenario for the algorithm and derive the big O 6, Describe the worst case scenario for the algorithm and derive the big Ob. Counting the total number of characters that have a duplicate within a string. (i.e. gigi the gato would result in 7 (g x 3 i x 2 +tx 2)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package abcdec;

import java.util.ArrayList;

import java.util.List;

public class DuplicateCounter {

public static void main(String[] args) {

String str="gigi the gato";

int count;

int finalcount=0;

List<String> checkArrayList=new ArrayList<String>();

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

count=0;

for(int j=i;j<str.length();j++){

if(str.toLowerCase().charAt(i)==str.toLowerCase().charAt(j) && str.charAt(i)!=' '

&& str.charAt(j)!=' ' &&

checkArrayList.indexOf(String.valueOf(str.charAt(i)))==-1){

count++;

}

}

checkArrayList.add(String.valueOf(str.charAt(i)));

if(count>1){

finalcount+=count;

}

}

System.out.println("Result is :"+finalcount);

}

}

Expected output:

Add a comment
Know the answer?
Add Answer to:
Answer B java Problem 2 For each problem given below, do the following: 1. Create an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT