Question

In: Computer Science

Problem 1: Given an array A[0 ... n-1], where each element of the array represents a...

Problem 1:

Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election.

Problem 2:

How do we find the number which appeared maximum number of times in an array?

( Use Java and an original code )

Solutions

Expert Solution

Problem 1 : To find the maximum votes for a candidate we can use hashMap and find the occurance of each item in the array.

Output :

Problem 2 : This is same as above problem as the technique used to solve above problem is : maximum frequency element in an array. but I have given screenshot of that code too.

Output : element with max frequency : 1


Related Solutions

Given an array A[0 … n-1], where each element of the array represent a vote in...
Given an array A[0 … n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
Using Java, Given an array A[0 ... n-1], where each element of the array represent a...
Using Java, Given an array A[0 ... n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
Need these written in Java script please Problem 1: Given an array A[0 ... n-1], where...
Need these written in Java script please Problem 1: Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election. Problem 2: How do we find the number which appeared maximum number of times in an array?
Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. [Please write a recursion function!] Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at,...
Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at, and get stuck at, index...
Consider the element uniqueness problem: check whether all the elements in a given array of n...
Consider the element uniqueness problem: check whether all the elements in a given array of n elements are distinct answer in pseudo code places
You are given a set S of n real numbers where for each element x ∈...
You are given a set S of n real numbers where for each element x ∈ S, 1 < | x | < 10. You are also given a black box that returns true if there is some combination (x, y, z) ∈ S such that x · y = z. Say the black box returns only z. Write an O(n log n) algorithm to find x and y. In other words, given a set S with n real numbers...
Suppose that each row of an n × n array A consists of 1’s and 0’s...
Suppose that each row of an n × n array A consists of 1’s and 0’s such that, in any row of A, all the 1’s come before any 0’s in that row. Assuming A is already in memory, describe a method running in O(n log n) time (not O(n2) time!) for counting the number of 1’s in A.
Given an array A[1..n] of integers - all of whose numbers are in the range [0,...
Given an array A[1..n] of integers - all of whose numbers are in the range [0, n^3 − 1] give an algorithm which sorts them in O(n) time.
In Java, write a program that given an array A[1...n] and a value S finds 0...
In Java, write a program that given an array A[1...n] and a value S finds 0 < i < j < n such that A[i] + A[j] = S
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT