Untitled

  1. prestoring and fetching

  2. why hashing?

    1. if number
    2. for i<n
    3. arr[i} == number
    4. cnt = cnt+1; -^
    5. return cnt

    Untitled

  3. now, hashing is → prestoring/ fetching

    1. a array of size 13

    2. with initial as 0; it is a hash array

      Untitled

      Untitled

    3. updating with the iteration

  4. code

    1. int hash[13];
    2. for(int i =0; i<n;i++){
    3. hash[arr[i]]++;
    4. }
    5. cout << hash[number] <<endl;
  5. one imp thing for 10^7 will not go for the array

    1. if array it will be max 10^6

    Untitled

    1. can we do character hashing?

      1. yes
      2. Q→ quries
        1. a→1
        2. b→2
        3. c→3
       ![Untitled](<https://prod-files-secure.s3.us-west-2.amazonaws.com/94b73934-74f9-494c-9e82-21f4a31e6ebf/66777cb8-658d-485d-ac2a-fdc72e51f587/Untitled.png>)
      
    2. aperently the formula will be character - ‘a’

     then, e-a =4,
     
     vagera vagera
    

    Untitled

  6. problem 2- code

    1. int hash[26] = {0};
    2. for(int) s.size(); i++
      1. hash[s[i]-’a’] ++;
  7. always prefer arrays

  8. number hashing → stc/collection

    Untitled

  9. stl comes here: vahi ki 10^9 jitna isme nahi aa paye ga

    1. map and unordered map,

      1. map
        1. arr= 1,2,3,1,3,2

          Untitled

        2. code:

          1. map<long or int,int> mpp;

          2. for

            1. map[arr[i]]++
          3. itrate in map:

            1. for(auto it : mpp){
              1. it.first, it.second
    2. HashMap

      1. store all thing in sorted order:
      2. auto I : map
      3. map<char,int>
        1. mpp[s[i]]++;
      4. map: log(n)
    3. Unordered_map

      1. no perticulat order

        1. advantage: o(1);
      2. worst case: o(n);

      3. first case : take unordered_map → if tle, then go to normal map

        Untitled