Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

find _ mode ( arr: DynamicArray ) - > tuple [ DynamicArray , int ] : Write a standalone function outside of the HashMap class

find_mode(arr: DynamicArray)-> tuple[DynamicArray, int]:
Write a standalone function outside of the HashMap class that receives a dynamic array,
which is not guaranteed to be sorted. This function will return a tuple containing, in this
order, a dynamic array comprising the mode (most occurring) value(s) of the given array,
and an integer representing the highest frequency of occurrence for the mode value(s).
If there is more than one value with the highest frequency, all values at that frequency
should be included in the array being returned (the order does not matter). If there is only
one mode, the dynamic array will only contain that value.
You may assume that the input array will contain at least one element, and that all values
stored in the array will be strings. You do not need to write checks for these conditions.
For full credit, the function must be implemented with O(N) time complexity. For best
results, we recommend using the separate chaining hash map instance provided for you in
the functions skeleton code.
Example #1:
da = DynamicArray(["apple", "apple", "grape", "melon", "peach"])
mode, frequency = find_mode(da)
print(f"Input: {da}
Mode : {mode}, Frequency: {frequency}")
Output:
Input: ['apple', 'apple', 'grape', 'melon', 'peach']
Mode : ['apple'], Frequency: 2
Example #2:
test_cases =(
["Arch", "Manjaro", "Manjaro", "Mint", "Mint", "Mint", "Ubuntu",
"Ubuntu", "Ubuntu"],
["one", "two", "three", "four", "five"],
["2","4","2","6","8","4","1","3","4","5","7","3","3","2"]
)
for case in test_cases:
da = DynamicArray(case)
mode, frequency = find_mode(da)
print(f"{da}
Mode : {mode}, Frequency: {frequency}
")
Page 16 of 29

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

What is Aufbau's rule explain with example?

Answered: 1 week ago