• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

Formal Definition

The hashing store phase (Phase 1) is the process of iterating over an input sequence and populating a hash structure (array or hash map) with frequency counts or other aggregated information. It is the data-ingestion step of the two-phase hashing paradigm.

Explanation

Phase 1 is mechanical: choose your structure, loop through the input, and for each element, update its count. There is no decision-making, no comparisons, no conditional logic — just raw accumulation. This mechanical uniformity is why beginners can complete Phase 1 but then get stuck: the real thinking comes in Phase 2.

How It Works

  1. Initialize the structure: int freq[26] = {0} or unordered_map<char,int> freq
  2. Iterate through each character in the input string
  3. For arrays: compute index = ch - 'a', then freq[index]++
  4. For maps: simply freq[ch]++
  5. After iteration, the structure contains all frequency information

Visual Explanation

store_phase START Initialize Structure int freq[26] = {0} CHAR Get Next char from string START->CHAR UPDATE freq[ch - 'a']++ CHAR->UPDATE MORE More chars? UPDATE->MORE MORE->CHAR yes DONE Phase 1 Complete Frequencies Stored MORE->DONE no

Semantic Network

semantic_store_phase THIS Hashing Store Phase PRE1 Frequency Array THIS--PRE1 built from PRE2 Unordered Map Frequency THIS--PRE2 built from OUT1 Two-Phase Hashing THIS--OUT1 builds into OUT2 Hashing Retrieval Phase THIS--OUT2 builds into REL1 Character-to-Index Mapping THIS--REL1 related REL2 Character Hashing Use Cases THIS--REL2 related

Key Properties

  • Always O(n) time — must visit each element once
  • O(k) space where k is the domain size (for arrays) or O(m) where m is distinct elements (for maps)
  • Structure choice (array vs map) is locked in during Phase 1
  • No conditional logic — just increment operations
  • Order of iteration does not matter for frequency counting

Connections

Edge Cases & Gotchas

  • For empty strings, Phase 1 produces an empty structure — Phase 2 must handle this
  • For strings with a single character, the structure has one entry — still correct
  • For maps, repeated freq[ch]++ calls may trigger rehashing (amortized O(1), but costly)
  • Phase 1 cannot answer any question about the data until it completes — it is purely a gathering phase