Develop an algorithm for finding the most frequently occurring value in an array of numbers. Use a sequence of coins. Place paper clips below each coin that count how many other coins of the same value are in the sequence. Give the pseudocode for an algorithm that yields the correct answer, and describe how using the coins and paper clips helped you find the algorithm. (C++)
PSEUDOCODE:
mostFrequency(a[],n)
{
hashmap freq; //we create a hashmap to store the frequency of each number, which will initially be 0.
for(i in 0 to n-1)
freq[a[i]]++; //updating frequency
maxCount=0,max=0;
for(i in freq)
{
if(i.second>maxCount) //comparing frequency to maximum
{
maxCount=i.second;
max=i.first;
}
}
return max;
}
Following is a code in C++ for finding the most frequently occurring value in an array of numbers:
#include <iostream>
#include <unordered_map>
#include <stdlib.h>
#include <time.h>
using namespace std;
//function to count frequency of each number in the array
//and return the number with most frequency
int mostFrequent(int a[],int n)
{
//map to store frequency
unordered_map<int,int> freq;
for(int i=0;i<n;i++)
freq[a[i]]++; //updating frequency
int maxCount=0,max=0; //temporary maximum
for(auto i:freq)
{
if(i.second>maxCount) //comparing frequency to maximum
{
maxCount=i.second;
max=i.first;
}
}
return max; //returning number with maximum frequency
}
int main()
{
//we create an array of size 100 randomly filled with 0-9
//to test the function
srand(time(0));
int a[100],i;
for(i=0;i<100;i++)
a[i]=rand()%10;
cout << mostFrequent(a,100);
}
Develop an algorithm for finding the most frequently occurring value in an array of numbers. Use...
1) (5 pts) Consider the problem of finding the mode (most frequently occurring value) in an array. John attempts to solve the problem recursively. His strategy is to recursively call his mode function on the left half of the array and the right half of the array, and then use these answers to calculate the mode of the whole array. Assuming that his function only returns the mode and nothing else, why is his strategy doomed to fail?
The process of finding the largest value is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. Write a Ruby application that allows a user to input a series of 10 integers and determines and prints the largest integer. Your program should use at least the following three variables: a) counter: A...
Describe an algorithm for finding the maximum (Large) value infinite sequence of integer 1.1 /10 points: Write a single sentence de- scribing what the question is asking 1.2 /10 points: Provide a list of other useful resources and references. 1.3 /10 points: Give a list of key assumption: and general observations /10 points: Summarize your calculati and other work /10 points: Discuss your solution, a plain why you believe it is correct
Question 1 This measure of central tendency provides the value that is most frequently occurring in a data set a. mode b. median c. mean d. distribution Question 2 This measure of central tendency can be affected by outliers a. mode b. median c. mean d. distribution e. A and B f. A, B, and C Question 3 Data sets can have more than one mode a. True b. False Question 4 There are how many measures of central tendency...
Here is a recursive algorithm that answers the same question as posed on Group HW3, finding the number of people who are taller than everyone before them in line. NumCanSeeRec(a1,... , an : list of n 2 1 distinct heights) (a) ifn -1 then (b return 1 (c) c= ŅumCanSeeRee(a1, , an-1) d) for i:- 1 ton- 1 (e) if a, an then return c (g) return c+1 Answer the following questions about this algorithm. Please show your work. (a)...
JavaScript - I need help formulating executable code for the following problem. 7.15 The process of finding the largest value (i.e., the maximum of a group of values) is used frequently in computer applications. For example, a script that determines the winner of a sales contest would input the number of units sold by each sales person. The salesperson who sells the most units wins the contest. Write a pseudocode ode algorithm and then a script that inputs a series...
I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...
Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.) 2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...
:) Problem: ??? Your task: implement in CH the algorithm solution shown below. Then analyze it and explain, using just one or two sentences, what it does. Write this explanation as a comment at the top of your program. This explanation will be worth 5 points of your total grade. Do not be too detailed (for example, do not write it opens a file and then declares variables, and then reads from a file...), it should look like the problem...
Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...