Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Class ArrayListClass in C++ Create an array class that has an array of

ID: 3681156 • Letter: C

Question

Create a Class ArrayListClass in C++

Create an array class that has an array of 27 List Classes

Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name.

Again - ignore index 0. index 1 is A, index 2 is B, index 3 is C... index 26 is z.

Create a file of 260 random ordered last names... 10 each for each letter...

Read in the file one name at a time, store/add each Name in the correct index LIST element.

( See File I/O lecture - this week if you need a review of File I/O)

Search for a Name to see if it in the LIST class.

Print out the ALL names found on each list..

please someone helps me with the assignment with an proper soultion that meets the requirment.

Explanation / Answer

PROGRAM CODE:

package com.chegg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class GenAlphabetCodes {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);
System.out
.println("Please enter any length number but combination of 1 to 26 ....... ");
String val = input.next();

System.out.println("All possible Alphabet codes for the give Number: "
+ val);
for (String string : decode(val)) {
System.out.println(string);
}

}

public static Set<String> decode(String in) {
char curChar = 'a';
Map<Integer, Character> numberToChar = new HashMap<Integer, Character>();
for (int i = 1; i <= 26; i++) {
numberToChar.put(i, curChar);
curChar++;
}
return decodeHelper(numberToChar, in, 0, new ArrayList<Character>());
}

private static Set<String> decodeHelper(
Map<Integer, Character> numberToChar, String in, int charAt,
ArrayList<Character> arrayList) {
Set<String> result = new HashSet<String>();
if (charAt >= in.length()) {
String str = "";
for (char c : arrayList) {
str += c;
}
result.add(str);
return result;
} else {
int charCode = Integer.valueOf(in.charAt(charAt) + "");
if (charCode == 0) {
int precCharCode = Integer.valueOf(in.charAt(charAt - 1) + "");
if (precCharCode == 1)
charCode = 10;
if (precCharCode == 2)
charCode = 20;
}
char curChar = numberToChar.get(charCode);
arrayList.add(curChar);
result.addAll(decodeHelper(numberToChar, in, charAt + 1, arrayList));
arrayList.remove(arrayList.size() - 1);
if (in.length() > charAt + 1) {
charCode = Integer.valueOf(in.substring(charAt, charAt + 2));
if (charCode <= 26) {
curChar = numberToChar.get(charCode);
arrayList.add(curChar);
result.addAll(decodeHelper(numberToChar, in, charAt + 2,
arrayList));
arrayList.remove(arrayList.size() - 1);
}
}
}
return result;
}
}


Output:
Please enter any digit number but combination of 1 to 26 .......
2010
All possible Alphabet codes for the give Number: 2010
taj
baj
btj
tj
btaj

TIME COMPLEXITY:

Time complexity of Dynamic Programming solution is O(n) as you calculate each i only once.
Time complexity of recursive method is 2^(n-1) worst case