please convert the code to C language   // C++ program to find minimum deletion  // to make all elements same #include using namespace std; int minimum_no_of_deletion(vector arr, int n) {     //create a hash table where for each key      //the hash function is h(x)=x     //we will use stl map as hash table and      //will keep frequencies stored     //so say two keys are mapping to the same location,

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please convert the code to C language

 

// C++ program to find minimum deletion 
// to make all elements same
#include <bits/stdc++.h>
using namespace std;

int minimum_no_of_deletion(vector<int> arr, int n)
{
    //create a hash table where for each key 
    //the hash function is h(x)=x
    //we will use stl map as hash table and 
    //will keep frequencies stored
    //so say two keys are mapping to the same location, 
    //then the location will have value 2
    //instead of the keys itself
    map<int, int> hash;

    for (auto i : arr) { //for each number
        hash[i]++;
    }

    //now to make all elements same
    //we need to keep only the keys with 
    //maximum frequency
    //we need to delete the other keys

    //so find the key with max frequency
    int maxfreq = 0;
    for (auto it = hash.begin(); it != hash.end(); it++) {
        if (it->second > maxfreq) {
            maxfreq = it->second;
        }
    }

    //so we need to dlete rest of 
    //the elements n-maxfreq
    return n - maxfreq;
}

int main()
{
    int n;
 
    cout << "Enter number of elements\n";
    cin >> n;

    vector<int> arr(n, 0);

    cout << "Input the array elements\n";

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    cout << "Minimum number of deletion required to make all elements same is: ";
    cout << minimum_no_of_deletion(arr, n) << endl;
    
    return 0;
}

 

Output:

 

Enter number of elements
8
Input the array elements
12 13 14 12 12 15 12 17
Minimum number of deletion required to make all elements same is: 4
Transcribed Image Text:Enter number of elements 8 Input the array elements 12 13 14 12 12 15 12 17 Minimum number of deletion required to make all elements same is: 4
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Potential Method of Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education