From 8c07da0e4c733f7ab57bd7f70f215881c91c2a04 Mon Sep 17 00:00:00 2001 From: Smara2026 Date: Thu, 16 May 2024 17:21:03 +0530 Subject: [PATCH] Added Hashing using arrays and maps Added Hashing using arrays and maps --- Hashing_using_array.cpp | 21 +++++++++++++++++++++ Hashing_using_map.cpp | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Hashing_using_array.cpp create mode 100644 Hashing_using_map.cpp diff --git a/Hashing_using_array.cpp b/Hashing_using_array.cpp new file mode 100644 index 0000000..b9468ae --- /dev/null +++ b/Hashing_using_array.cpp @@ -0,0 +1,21 @@ +// Hashing is a technique to find out the frequency of an element in an array at O(N) time complexity. +// This method uses hash array to perform hasing. +#include +using namespace std; +int main(){ + int n; //size of array + cin>>n; + int max_input=INT_MIN; + int nums[n]; //array to be hashed + for(int i=0;i>nums[i]; + max_input=max(max_input,nums[i]); + } + int hash[max_input+1]={0}; + for(int i=0;i>desired_num; + cout<<"The frequency of "< +using namespace std; +int main(){ + int n; //size of array + cin>>n; + int nums[n]; //array to be hashed + for(int i=0;i>nums[i]; + } + map hashmap; + for(int i=0;i>desired_num; + cout<<"The frequency of "<