Question

1) (5 pts) Consider the problem of finding the mode (most frequently occurring value) in an array. John attempts to solve the

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This strategy is doomed to fail since it misses on the fact that there can be an element in both left half and right half such that its total frequency exceeds those of individual modes of left half and right half. Consider the array :

   left half    right half

1, 2, 2, 3, 3, 2, \ \ \ \ \ 3, 3, 5, 5, 5, 1

The left half has mode 2(frequency 3), & the right half has mode 5(frequency 3), So his algorithm would consider 2 & 5 for overall mode, however it is to be noted that the element 3 has overall frequency 4, which should make it the mode despite having lower frequencies in left and right sub arrays. Morever since, the function only returns mode and not its frequency, we have no means of deciding whether the mode from left half has more frequency than the mode in right half or vice-versa.

The problem with this algo is as we continue to subdivide arrays, it will only give correct result if the mode occurs at consecutive places:

Recursion level 0 1 2 2 3 3 2    3 3 5 5 5 1
Recursion level 1 1 2 2 3 3 2 3 3 5 5 5 1
Recursion level 2 1 2 2 3    3    2 3    3    5 5    5    1
Recursion level 3 1 2 2 3 3 2 3 3 5 5 5 1
Recursion level 4 1 2 2 3 3 2 3 3 5 5 5 1

Thus we keep recurring as above table until finally we get subarray of size 1. But, now what? These individual subarrays of size 1 would have mode same as their only element. Combining them to get mode of subarray of size 1 or subarray of size 2 with same elements would work fine, but it won't work other wise. Consider these case of recorsion level 3:

CASE 1: We have subarray [1], since it is the only element, the mode would be 1.

CASE 2: We have subarray [2,2], which is divided as [2] & [2], each having mode 2 and this could be aggregated to get overall mode 2.

CASE 3: We have subarray [3,2], which is divided as [3] & [2], having mode 3 & 2 respectively. Now we have an ambiguity to chose whether 3 or 2 or both as the mode for the subarray of size 2. This is where the algorithm would fail.

Thus the ambiguity in aggregating the mode from left half & right half dooms this algorithm to fail.

Add a comment
Know the answer?
Add Answer to:
1) (5 pts) Consider the problem of finding the mode (most frequently occurring value) in an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT