Let's say I have the next array of 9 numbers: 1, 2, 2, 4, 2, 2, 3, 2, 1. Show
Em.♦ 45.1k12 gold badges134 silver badges147 bronze badges asked May 22, 2017 at 7:48
1 Two is the most frequent (spelled frequent) sounds fine to me. Alternatively, you could write something like
I think the "one word" you are looking for is mode. It is mathematical terminology.
answered May 22, 2017 at 7:55
Em.♦Em. 45.1k12 gold badges134 silver badges147 bronze badges 1 "Most frequent" seems reasonable to me. If you really need a single word for some reason, you could choose commonest:
For a mathematically-rigorous word, you should use mode:
answered May 22, 2017 at 10:50
Toby SpeightToby Speight 2,01012 silver badges23 bronze badges 6 Some more suitable words: Predominant, Preponderant, Principal. All can be used to mean "most frequent", and are better known than "mode" (which is rarely if ever used by anyone who isn't a mathematician) while also sounding more professional than something like "commonest". E.g. "The preponderant number is 2". answered May 22, 2017 at 15:03
BenubirdBenubird 2491 silver badge4 bronze badges 4 You could say "prevalent" or "abound" For arrays the fixed phrase "most frequent value" is widely used. In mathematics the term "mode" is common. Here's a good explanation of what a mode is - Most frequent values in array. answered May 22, 2017 at 15:40
SovereignSunSovereignSun 24.6k34 gold badges136 silver badges253 bronze badges As the question mentions an array of numbers, seems to me mode is absolutely the correct answer (and had I got here quicker I think that would have been my one-word answer). This used to be taught at primary level in the UK (until 2015), so not obscure terminology :) answered May 22, 2017 at 22:30
You must log in to answer this question.Not the answer you're looking for? Browse other questions tagged .Level: Medium Asked in: Facebook, Uber Understanding the ProblemProblem Description: Given an array A[] of size n, find the most frequent element in the array, i.e. the element which occurs the most number of times. It is assured that at least one element is repeated. For example: Input: A[] = {3, 9, 1, 3, 6, 3, 8, 1, 6} Output: 3 Input: A[] = {1, 9, 1, 3, 2, 3, 10} Output: 1 Possible questions to ask the interviewer:-
Brute force and Efficient SolutionsWe will discuss three possible solutions for this problem:-
1. Brute Force ApproachFor each element, scan the entire array to find its duplicates. Maintain two variables max_freq and ans tostore the maximum frequency and the element with that frequency respectively. Pseudo-Code
Complexity Analysis Time Complexity: O(n²) (Why?) Space Complexity: O(1) Critical ideas to think!
2. Using SortingIf we sort the array, all the duplicate elements will get lined up next to each other. We can now linearly find the frequency of all elements in the array. This approach also ensures that frequency is calculated only once for each unique element. Pseudo-Code
Complexity Analysis Time Complexity: Sorting the array + Linear Traversal of array = O(nlogn) + O(n) = O(n) Space Complexity: O(n), if we use merge sort and O(1) if we use heap sort Critical ideas to think!
3. Using Hash TableWe can create a hash table and store elements and their frequency counts as key value pairs. Solution Steps 1. Create a Hash Table to store frequency of each element in the given array. Consider elements in the array as key and their frequency as value
3. During the iteration, we are also storing the most frequent element and its frequency in the parameter ans and max_freq respectively. Pseudo-Code
Complexity Analysis Time Complexity: O(n) (Why?) Space Complexity: O(n), for storing the Hash Table Critical ideas to think!
Comparison of different solutionsSuggested problems to solve
If you have any more approaches or you find an error/bug in the above solutions, please comment down below. Happy Coding! Enjoy Algorithms! AfterAcademy Data Structure And Algorithms Online Course - Admissions OpenWhat is the most frequently occurring value called?The mode is the most commonly occurring value in a distribution. This table shows a simple frequency distribution of the retirement age data. The most commonly occurring value is 54, therefore the mode of this distribution is 54 years.
What is median in statistics?Median, in statistics, is the middle value of the given list of data when arranged in an order. The arrangement of data or observations can be made either in ascending order or descending order. Example: The median of 2,3,4 is 3. In Maths, the median is also a type of average, which is used to find the centre value.
What do you call the value that occurs with the highest frequency in a data set?In statistics, the mode represents the most common value in a data set. Therefore, the mode is the value that occurs with the highest frequency in a data set (Mann 2012).
Which is the most frequent value mean median mode?The mode is found by collecting and organizing the data in order to count the frequency of each result. Thus mode is the most frequently observed value.
|