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
  • Searching/sorting tasks and efficiency analysis - Big-oh For each problem given below, do the following: 1....

    Searching/sorting tasks and efficiency analysis - Big-oh 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. Count the operations performed by the algorithm. Express the count as a...

  • For each problems segment given below, do the following: Create an algorithm to solve the problem...

    For each problems segment given below, do the following: Create an algorithm to solve the problem Identify the factors that would influence the running time, and which can be known before the algorithm or code is executed. Assign names (such as n) to each factor. 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...

  • S19-A6.pdf 2/5 Rutgers University CS111 - Inlroduction to Computer Science Spring 2019 Problem 5 Big-oh For...

    S19-A6.pdf 2/5 Rutgers University CS111 - Inlroduction to Computer Science Spring 2019 Problem 5 Big-oh For cach problen given below, do lhe following 1. Creste a algrithm in psudood to solve the proble 2. Identify the factors that would influence the running time of your algorithm. For exarple, if your alorithm ia to search an array th fator that influeuxs the runnin time is the array size. Assign names (such as n) to each factor. 3. Count the operations performed...

  • 9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time effi...

    9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time efficiency class of your algorithm. duplicate search problem input: a vector V of comparable objects output: an element of V that appears more than once in V, or None if no such element exists 9-2. For each of the following problems: design a reduction algorithm a hash table or...

  • Write pseudocode to solve the following problem: You are given an array A[1...n] whose each element...

    Write pseudocode to solve the following problem: You are given an array A[1...n] whose each element is a point of the plane (x,y). You need to sort the array so that points with lower x-coordinates come earlier, but among points with the same x-coordinate, the ones with larger y-coordinate come earlier. So, for example, if the array contains: (1,2), (1,4), (7,10), (11,3), (14,1), (7,2) The output, in this case, should be: (1,4), (1,2), (7,10), (7,2), (11,3), (14,1) Analyze the running...

  • 1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark...

    1. [5 marks Show the following hold using the definition of Big Oh: a) 2 mark 1729 is O(1) b) 3 marks 2n2-4n -3 is O(n2) 2. [3 marks] Using the definition of Big-Oh, prove that 2n2(n 1) is not O(n2) 3. 6 marks Let f(n),g(n), h(n) be complexity functions. Using the definition of Big-Oh, prove the following two claims a) 3 marks Let k be a positive real constant and f(n) is O(g(n)), then k f(n) is O(g(n)) b)...

  • 6. Consider the following basic problem. You're given an array A consisting of n integers A[1],...

    6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...

  • Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do...

    Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1 1. Describe what it does and compute what value is returned when the input is the list {1, 2, 3, 4, 5}. (Hint: We're using 0-based array indexing, so 0 would represent the index of the first element, 1 the second element, etc.) 2. Identify and describe the worst-case input. 3. Identify and...

  • Consider the following problem: given n positive integers, separate them into two groups such that adding...

    Consider the following problem: given n positive integers, separate them into two groups such that adding all the numbers in one group gives the same result as adding all the numbers in the other group. For example, if the numbers are 1, 2, 3, 4, then the two groups could be {1, 4} and {2, 3}, which both sum to 5. For another example, if the numbers are 5, 6, 11, then the two groups could be {5, 6} and...

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

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