An anagram is a word or phrase formed by rearranging the letters of another. For example, “listen” and “silent” are anagrams of one another.
Consider an array called ALPHA of size 26 initialised to contain only zeros. Also consider a function LTR2NUM() which accepts a single character and returns it's position in the English alphabet. For example, LTR2NUM('a') and LTR2NUM('z') return 1 and 26 respectively.
Given a Collection of letters called LETTERS, construct an algorithm to accumulate the total number of each type of letter in corresponding ALPHA index locations. For example, if the letter 'b' occurs 7 times in LETTERS then, once the algorithm has completed, ALPHA should equal 7.
Construct an algorithm that outputs True if every value in ALPHA is equal to zero
Assume now that the two algorithms from a) and b) were augmented to form functions called createAlpha() and isZero() respectively.
The function createAlpha() accepts as input a Collection of letters and returns a new array called ALPHA of size 26 where the total number of each type of letter in the Collection provided as input is accumulated at corresponding ALPHA index locations. For example:
createpAlpha(["a","a","b","e","z","z","z"]) → [2,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3]
The function isZero() accepts as input an array of numbers and returns a boolean to indicate whether or not the array provided is full of zeros. For example:
isZero([0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) → false isZero([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) → true
Given an empty array called ARR of size 26 and two Collections of letters, one called WORDA and another called WORDB, construct an algorithm to return true if WORDA is an anagram of WORDB, otherwise output false.
Extended Response11 MarksCommunity
16 Uses37 Views1 Like