java - Determining the element that occurred the most in O(n) time and O(1) space -


Let me start by saying that this is not a question of homework, I am trying to design a cash whose removal policy Depends on the most happening entries in the cache. In software terms, let's say we have an array with different elements and we want to find the element that is the most. For example: {1,2,2,5,7,3,2,3} 2 should be returned. Since I'm working with the hardware, the solution for the naive O (N ^ 2) will require a tremendous hardware overhead. The smart solution to use the hash table works well for the software because the hash can change the size of the table but in the hardware, I have a fixed size hash table, maybe this is not big, so the collision wrong decisions Will cause. My question is, in the software, can we solve the problem of O (n) time of complexity and o (1) space?

a o (n) time, o (1) Space solution, not least for generic case

As we resolve this, we get its solution (to determine whether all the elements in the list are different or not), which is the Î ?? (N log n) has been proven to take time when computer memory is not used while using index elements, if we use elements to be used on the basis of computer memory, then values Looking at the limitless limit, it contains at least Î ?? (N) Space is required to reduce the problem, considering that problem, limits for that problem apply the same limit on this problem.

However, speaking practically, this category will be heavily compelled, if not for a reason other than in general, each element is usually given a fixed size (such as a 32-bit integer) Uses to store. If this is the case, it will probably allow the O (n) time, O (1) space solution due to very slow and very high space reasoning Factors are involved (as the complexity of time and space depends on the extent of values).

2 options:

  • Keeping an array of the number of elements (array index element) Output more often. ). But technically this is a hash table approach, so the static factor is too much to be acceptable for it.

    There are related options (in-place variants, which are similar to quicker) and

  • Repeat and split the data based on recursive on a selected axis (through slipping) and split.

    After we sort only we repeat through the array, constantly keep track of the maximum number of elements.

    This O (n log n) time and o (1) space.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -