Algorithm: There is a series of integers, this string of numbers indefinite, a total of N, to find the number of occurrences of the most numbers _ algorithm

Source: Internet
Author: User

There is a series of integers, the number of numbers is indefinite, a total of N, to find out the number of the most frequent (the original question is to find the number of occurrences greater than the N/2)

What is the general algorithm for this problem?

General algorithm

Loop array, find the same number for a number, find the total plus one, and mark the same number as-1, and then no longer compute in the loop

Repeat the loop until you find the result, and some of the tips can end prematurely, which means that if a number is more than N/2, it is definitely the result.

A Veteran's algorithm

He fully analyzed the same number of laws, the same number of their binary value, decimal value, hexadecimal values are equal

So that when you loop through the data, put the data into an array of 16 based on its hexadecimal lowest bit, so that after a loop, the array always records the number of occurrences of the data, such as the first digit of the hexadecimal number is 0, then add the place of the array "0" to one, Finally, compare the data to the largest number in the array until the end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.