Answer:
Follows are the solution to this question:
Explanation:
In the previous algorithm has also been fine yet un optimal and also gives O(n^2) computation time, that is is very powerful. It is a proposed algorithm, that has been arriving because its method has also been defined, its sorting provides the O( nlogn), which is much better than the last time complexity.
When did I consider repeat figures, it is another aspect to note at the same figures arise as figures are ordered, for instance, the number is 1, 2, 1, 3, 2, 1, 3. It becomes such as these number once sorted 1 , 1 , 1, 2 , 2 , 3 , 3.
The smaller number 1, that's also 3 times combined in the second-largest amount, which is 2 times, but instead number 3, that's 2 times together consequently, with one pass in series, they can conveniently check the amount of duplicate.
It is a particular characteristic that appears 2 or more times, so it gets the same increases and amount for multiple copies when it sorted, and search for a specific transaction if it is equal with the original weeks. If there is indeed a problem we have an amount more than 2 times for the same amount we need additional iterations.
Therefore, the second 1 method fits it's very first 1 and its increase in multiple copies, however, the third 1 is the same for the second 1, so the amount of double for step 1 was already increased again so the same number also has an element following. To remove this problem, a hashmap keeps track as a number, which crossed 1 time must be initialized the algorithm and doesn't search for amount again.
The algorithm functions as follows:
1.initialize a hashmap which defaults to 0.
2.Now sorted array with the second position element.
3.Check if the element hashmap value is 0 as well as the previous variable has the same value.
4. Increase the number of multiple copies and fill out hazmap element to 1 if both conditions and AND conditions become valid.
5. if the element and move to the next item if the state of AND is wrong.
6. go to 3 and take the same steps to the end of the array.