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

In pseudocode, write a function that takes as input an array of strings, and ret

ID: 3841440 • Letter: I

Question

In pseudocode, write a function that takes as input an array of strings, and returns as output a dictionary containing key-value pairs, where the keys are the strings that appear in the input array and the value is an integer representing the number of times the key appears in the array. For example, if the input is the array ["bat", "box", "boot", "boot", "boot", "bat"], then the output should be the dictionary {"bat": 2, "box": 1, "boot": 3}. You may use the following dictionary operations: create a new empty dictionary, check if a key is in the dictionary, insert a key-value pair, set the value of a key that is already in the dictionary to a new value.

Explanation / Answer

Algorithm(string key[],int n)

{

int a[],x=0; //Here a will take the new counts and x is for accepting the new index in Dictionary

string y[]; // This is used to take the new dictionary words

for(int i=0;i<n;i++) //Loop all the elements

{

if(key[i]!="") //As when we are reading already read element to be empty we are checking if it is empty

{

y[x]=key[i]; //If it is not empty we are assigning the value

a[x]=1; //Assigning Count

for(int j=i+1;j<n;j++) //This is for Checking the Remaining Values

{

if(y[x]==key[j]) // We are Comparing the values

{

a[x]+=1; //If it is equal we are incrementing Count

key[j]="";// We are assigning Null value to it

}

}

}

}

for(i:0 to x)

print y[i] and a[i] // We are printing Values

}