Question: These are java related questions. Thank you. ArrayStringBag code: package stringbagarray; import java.util.Arrays; import java.util.ArrayList; import java.util.Vector; public final class ArrayStringBag implements ArrayStringBagInterface { private
These are java related questions. Thank you.

ArrayStringBag code:
package stringbagarray; import java.util.Arrays; import java.util.ArrayList; import java.util.Vector; public final class ArrayStringBag implements ArrayStringBagInterface{ private int numEntries = 0; private String[] bag; private static final int DEFAULT_CAPACITY = 2; private final int MAX_CAPACITY = 10; /o-arg constructor public ArrayStringBag() { this(DEFAULT_CAPACITY); } //1-arg constructor public ArrayStringBag(int sz) { if ( sz > MAX_CAPACITY) throw new IllegalStateException("Attempt to create Bag larger than Maximum allowed capacity"); String[] strArr = new String[DEFAULT_CAPACITY]; bag = strArr; } public int getSize() { return this.bag.length; } /** * This method removes the last item * * @return true if remove was successful */ public boolean remove() { if(this.getSize() == 0) return false; else { bag[this.numEntries - 1] = null; return true; } } public boolean isItEmpty() { return bag.length == 0; } /** * This method adds a given string to the bag * @param act string being added * @return true if add was successful */ public boolean add(String str) { if(this.isBagFull()) { doubleBagCapacity(); } String[] tmpArr = this.bag; tmpArr[numEntries] = str; numEntries += 1; return true; } /** Removes specified item from the bag @return success or failure @param act item marked for deletion */ public boolean remove(String act) { int itemIdx = 0; int idxCount = 0; boolean found = false; while(!found) { if(bag[idxCount].equals(act)) { itemIdx = idxCount; found = true; } else idxCount++; } if(itemIdx == 0) // item for deletion not found return false; else if(itemIdx == numEntries - 1) { bag[itemIdx] = null; } else { bag[itemIdx] = bag[numEntries - 1]; // put last item in place of bag[numEntries - 1] = null; } numEntries--; return true; } public int getCount(String str) { int countOf = 0; for(int i = 0; i = this.getSize(); } public int getCountOf(String str) { return this.getCount(str); } }
1. There are 2 algorithms being used in your coding implementation. Time complexity of the first is based on the n + 5n + 7 operations whereas that of the second one is based off of 4n? operations. [15 points] Outline the summary in terms of the time requirements for these 2 algorithms both when the data count (n) is small and when it is large. Is one faster than the other for the same set of element count? Hint: Create a matrix showing computation with a few n small values of n, and then show the same for a few exponentially large values of n, for each of the two algorithms. Use slide 17 from Feb 20 class presentation on Algorithm Efficiency 2. Consider the following pseudo code [5 points] int total = 0; for (int i = 1; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
