Skip to content

Commit 4de89e8

Browse files
committed
Added hashing.cpp code
1 parent e792498 commit 4de89e8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

hashing.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Hashing help us to count the frequency of an element in the array in time complexity of O(N). so this is
2+
// an efficient method for calculating the frequency of an element in array
3+
4+
5+
#include<bits/stdc++.h>
6+
using namespace std;
7+
const long long int M=1e5+5;
8+
int main(){
9+
int n; //size of the array
10+
cin>>n;
11+
int a[n];
12+
int hash_arr[M];
13+
for(int i=0;i<M;i++)hash_arr[i]=0;
14+
for(int i=0;i<n;i++){
15+
cin>>a[i];
16+
hash_arr[a[i]]++;
17+
}
18+
int x; // Number whose frequency we want
19+
cin>>x;
20+
cout<<hash_arr[x];
21+
}

hashing.exe

45.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)