Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may assume that each string ONLY contains lower case

Complete the recoverMessage() function, which takes a list of equal-length strings as its single argument. You may assume that each string ONLY contains lower case letters;there are no spaces,digits,uppercaseletters,or punctuation symbols in any of the source strings The function returns a single string whose length is equal to that of any one of the source strings. This function works as follows: 1. Create a dictionary that will hold the frequency of each letter (you can either pre-populate this with all 26 letters, or you can simply create an empty dictionary and use the setdefault() function to add new letters to the dictionary as you encounter them).

2. Create a variable to hold the recovered string (this will initially be the empty string).

3. For each index value: (a) Examine the letter at that index in each source string. Update the dictionarys count for that letter(i.e.,ifyousee a(nother) "b", add 1 to the integer value associated with the key "b" in your dictionary). (b) When you have evaluated all of the source strings at the given index, determine which dictionary key (letter) has the largest value associated with it (for each key in your dictionary, examine its value and compare it to the largest value that youve seen so far). Here is pseudocode for one possible sub-algorithm:

most_common = value of index 0 from your dictionarys list of keys for each key k in your dictionary:

if ks value is greater than the value associated with most_common: set most_common to k

Append that letter to your "recovered string" variable. For example, given the dictionary {"a":3, "b":5, "c":4}, your code would return "b" as the most frequent letter. If two or more letters tie for the highest frequency in a given position, you may select any one of them as the "winner"; we will ultimately use context and human intuition to determine what the correct letter should have been.

(c) Clear or reset the contents of the dictionary in preparation for the next round of your loop.

4. When the outermost loop ends, return the value of your recovered string.

Function: recoverMessage(["edferfthm", "aqvorithm", "algbridnn", "glgoxirhm", "iogleielb", "alwxuithj", "wlaobifhm"]) RETURN VALUE: algorithm

Function:recoverMessage(["citputejncienje", "cebautersmjynzt", "comcntewsciunwb", "foxuuterscienfe", "jomvuzerociiavn", "tojeotesstfdiqe", "computezsciryce"]) RETURN VALUE:computerscienje OR computerscience

Function:recoverMessage(["ouanycrokk", "stwnyaraok", "rtraybrauk", "stinyfuslk", "stknlbrxzk", "hrirybraek", "sjofyborjd"]) RETURN VALUE:stinybrakk OR stonybrook OR one of several other variations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

Distinguish between the fovea centralis and the optic disc.

Answered: 1 week ago