Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

I am trying to finish a set of problems give to me by my teacher. I am using C I need to know about Arrays and How to find the mode inside an array.

OpenStudy (anonymous):

what do you mean by "mode"??

OpenStudy (anonymous):

The mode is the most frequently occurring element. This problem seems simple enough at first glance, but then you realize that an efficient solution requires playing with different kinds of data structures :) A C example is here: http://rosettacode.org/wiki/Averages/Mode#C but it seems way too complicated for my tastes.

OpenStudy (anonymous):

A simple way to do it is to sort the thing and then search for the longest-recurring element.

OpenStudy (anonymous):

http://ideone.com/Fpzxc

OpenStudy (anonymous):

It can be done without sorting as well. Just create a hash table to store element as key, and total no. of repetitions as value. Traverse the source array, and upate the hash table for each element detected. After traversal, iterate through the hash table to find the key with maximum value.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!