Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The relative frequency of a letter in a string is the number of times that the letter appears in the string divided by the total

The relative frequency of a letter in a string is the number of times that the letter appears in the string divided by the total number of letters in the string. Note that this is always a number between 0 and 1. Write a function max_relative_frequency(s) which takes as argument a string and returns the highest relative frequency of any letter in the string. This value is unique. There can be several letters that occur with an equal (highest) frequency, but in that case their relative frequency is the same. Consider only letters of the English alphabet (that is, 'a' through 'z'). For the purpose of counting occurrances, consider letters that differ only by case to be the same letter. For example, the letter 'n' occurs three times in the string "Non-even" (once in upper case, twice in lower case). For the purpose of counting the total number of letters in the string, count only letters. For example, the string '0 << c++ << 9' contains only one letter, 'c', so the relative frequency of 'c' in this string is 1. If the string contains no letter, the relative frequency is undefined and your function should return 0. Examples: The string 'sufficit' has 8 letters, and the most frequent letters are f and i, which both occur twice. Thus, the highest relative frequency is 2/8. The string 'Non-even' has 7 letters (- is not a letter), and the most frequent letter is n which occurs three times (one N and two n). Thus, the highest relative frequency is 3/7. Assumptions and restrictions: You can assume that the argument is a string. Your function must return a number between 0 and 1 (inclusive).

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago