<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="/static/feed.xsl" type="text/xsl" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:quartz="https://quartz.jzhao.xyz/ns">
  <script xmlns="http://www.w3.org/1999/xhtml" src="/static/scripts/xslt-polyfill-214fd525.js"></script>
  <title>/wiki / strings</title>
  <subtitle>Recent notes in /wiki / strings on Animesh Mishra</subtitle>
  <link href="https://animishraa05.github.io/wiki/strings" />
  <link rel="alternate" type="text/html" href="https://animishraa05.github.io/wiki/strings" />
  <category term="wiki/strings" />
  <id>https://animishraa05.github.io/wiki/strings</id>
  <updated>2026-09-02T05:29:25.227Z</updated>
  <contributor>
    <name>Animesh Mishra</name>
    <email>animesh.mishra818@gmail.com</email>
  </contributor>
  <logo>https://animishraa05.github.io/icon.png</logo>
  <icon>https://animishraa05.github.io/icon.png</icon>
  <generator>Quartz v4.6.0 -- quartz.jzhao.xyz</generator>
  <rights type="html">&amp;amp;copy; 2026 Animesh Mishra</rights>
  
  <entry>
    <title>_Index_of_strings</title>
    <link href="https://animishraa05.github.io/wiki/strings/_Index_of_strings" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/_Index_of_strings.md" />
    <summary>anagram-detection-via-hashing ascii-math-elimination character-hashing-use-cases character-to-index-mapping direct-array-access first-non-repeating-character frequency-array-vs-hash-map frequency-array hash-collision-overhead hash-map-flexibility hashing-retrieval-phase hashing-store-phase index-to-...</summary>
    <published>2026-09-02T05:29:25.227Z</published>
    <updated>2026-09-02T05:29:25.227Z</updated>
    <publishedTime>Sep 02, 2026</publishedTime>
    <updatedTime>Sep 02, 2026</updatedTime>
    
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;p dir=&quot;auto&quot;&gt;&lt;a href=&quot;../../wiki/strings/anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;anagram-detection-via-hashing&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ascii-math-elimination&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;character-hashing-use-cases&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;character-to-index-mapping&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;direct-array-access&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;first-non-repeating-character&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/frequency-array-vs-hash-map&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/frequency-array-vs-hash-map&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;frequency-array-vs-hash-map&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;frequency-array&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;hash-collision-overhead&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;hash-map-flexibility&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;hashing-retrieval-phase&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/hashing-store-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/hashing-store-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;hashing-store-phase&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;index-to-character-conversion&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;interview-decision-framework&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;known-range-assumption&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/map-traversal-method&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/map-traversal-method&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;map-traversal-method&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;memory-efficiency-array&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;most-frequent-character&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/strings-moc&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/strings-moc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;strings-moc&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/strings-summary&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/strings-summary&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;strings-summary&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/two-phase-hashing-patterns&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/two-phase-hashing-patterns&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;two-phase-hashing-patterns&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;two-phase-hashing&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;unordered-map-frequency&lt;/a&gt;
&lt;a href=&quot;../../wiki/strings/unordered-map-non-determinism&quot; class=&quot;internal alias&quot; data-slug=&quot;wiki/strings/unordered-map-non-determinism&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;unordered-map-non-determinism&lt;/a&gt;&lt;/p&gt;</content>
  </entry><entry>
    <title>anagram-detection-via-hashing</title>
    <link href="https://animishraa05.github.io/wiki/strings/anagram-detection-via-hashing" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/anagram-detection-via-hashing.md" />
    <summary>Formal Definition Anagram detection determines whether two strings are permutations of each other — that is, whether they contain the same characters with the same frequencies.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Anagram detection determines whether two strings are permutations of each other — that is, whether they contain the same characters with the same frequencies. The hash-based approach builds frequency structures for both strings and compares them. Anagrams produce identical frequency maps.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;are_anagrams&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mo&gt;⟺&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∀&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mtext&gt;freq&lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mtext&gt;freq&lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{are\_anagrams}(S_1, S_2) \iff \forall c, \text{freq}_{S_1}(c) = \text{freq}_{S_2}(c)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.06em;vertical-align:-0.31em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;are_anagrams&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;⟺&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0942em;vertical-align:-0.3442em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∀&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;freq&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2342em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3173em;&quot;&gt;&lt;span style=&quot;top:-2.357em;margin-left:-0.0576em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.143em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3442em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0942em;vertical-align:-0.3442em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;freq&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2342em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3173em;&quot;&gt;&lt;span style=&quot;top:-2.357em;margin-left:-0.0576em;margin-right:0.0714em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.5em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size3 size1 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.143em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3442em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Two strings are anagrams if one can be rearranged to form the other. The simplest correct approach is to count character frequencies for both strings and compare. This elegantly demonstrates the two-phase hashing pattern applied to two inputs simultaneously — Phase 1 runs twice (once per string), then Phase 2 compares the two structures.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Build frequency array/map for string 1 (&lt;code class=&quot;notranslate&quot;&gt;freq1&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Build frequency array/map for string 2 (&lt;code class=&quot;notranslate&quot;&gt;freq2&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;For arrays:&lt;/strong&gt; compare element by element — all 26 slots must match&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;For maps:&lt;/strong&gt; compare key-value pairs — all keys in one must exist in the other with the same values&lt;/li&gt;
&lt;li&gt;If all counts match, the strings are anagrams&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;For strings &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S_1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8333em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S_2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8333em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; over alphabet &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\Sigma&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;Σ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;Anagram&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mo&gt;⟺&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∀&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mtext&gt;count&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mtext&gt;count&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Anagram}(S_1, S_2) \iff \forall c \in \Sigma, \text{count}(S_1, c) = \text{count}(S_2, c)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Anagram&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;⟺&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7335em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∀&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;Σ&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;count&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;count&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;Anagram&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mo&gt;⟺&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;msub&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mtext&gt;count&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mtext&gt;count&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Anagram}(S_1, S_2) \iff \sum_{c \in \Sigma} |\text{count}(S_1, c) - \text{count}(S_2, c)| = 0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Anagram&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;⟺&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0771em;vertical-align:-0.3271em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.1786em;&quot;&gt;&lt;span style=&quot;top:-2.4003em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mrel mtight&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;Σ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3271em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;count&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;count&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph anagram_detection {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  S1 [label=&quot;String 1:\n&#039;listen&#039;&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  S2 [label=&quot;String 2:\n&#039;silent&#039;&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  P1_S1 [label=&quot;Phase 1\nBuild freq1&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  P1_S2 [label=&quot;Phase 1\nBuild freq2&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  F1 [label=&quot;freq1:\ne:1, i:1, l:1\nn:1, s:1, t:1&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  F2 [label=&quot;freq2:\ne:1, i:1, l:1\nn:1, s:1, t:1&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  COMPARE [label=&quot;Compare\nfreq1 == freq2?&quot; shape=diamond]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  YES [label=&quot;Anagram!&quot; fillcolor=&quot;#d4edda]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  NO [label=&quot;Not Anagram&quot; fillcolor=&quot;#ffe5cc&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  S1 -&gt; P1_S1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  S2 -&gt; P1_S2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  P1_S1 -&gt; F1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  P1_S2 -&gt; F2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  F1 -&gt; COMPARE&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  F2 -&gt; COMPARE&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  COMPARE -&gt; YES [label=&quot;yes&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  COMPARE -&gt; NO [label=&quot;no&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_anagram Pages: 1 --&gt;
&lt;svg width=&quot;358pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 358.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 202.54)&quot;&gt;
&lt;title&gt;semantic_anagram&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-202.54 354.16,-202.54 354.16,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;183.8&quot; cy=&quot;-99.11&quot; rx=&quot;84.28&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.8&quot; y=&quot;-95.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;265.36&quot; cy=&quot;-120.62&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;265.36&quot; y=&quot;-117.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M237.75,-113.34C237.87,-113.37 237.99,-113.4 238.11,-113.43&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;219.42&quot; y=&quot;-105.29&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;142.48&quot; cy=&quot;-25.44&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.48&quot; y=&quot;-22.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M173.59,-80.9C167.23,-69.57 159.08,-55.04 152.72,-43.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;144.65&quot; y=&quot;-54.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE3 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE3&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;110.74&quot; cy=&quot;-141.11&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;110.74&quot; y=&quot;-137.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE3 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M154.09,-116.2C149.03,-119.1 143.79,-122.11 138.78,-124.99&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.94&quot; y=&quot;-123.29&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;226.39&quot; cy=&quot;-171.9&quot; rx=&quot;101.81&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.39&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character Hashing Use Cases&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M194.33,-117.11C200.83,-128.22 209.15,-142.44 215.69,-153.61&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;225.27&quot; y=&quot;-138.06&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;162.26&quot; cy=&quot;-180.54&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;162.26&quot; y=&quot;-177.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M179.02,-117.18C175.48,-130.58 170.66,-148.78 167.1,-162.24&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;200.57&quot; y=&quot;-142.41&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;102.56&quot; cy=&quot;-76.64&quot; rx=&quot;102.56&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.56&quot; y=&quot;-73.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;First Non-Repeating Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M131.43,-84.63C131.31,-84.59 131.19,-84.56 131.06,-84.52&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;103.74&quot; y=&quot;-87.27&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;257.03&quot; cy=&quot;-56.82&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;257.03&quot; y=&quot;-53.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M213.58,-81.91C218.02,-79.35 222.59,-76.71 227.03,-74.15&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.31&quot; y=&quot;-69.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;206.1&quot; cy=&quot;-18&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.1&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M188.86,-80.71C192.51,-67.43 197.42,-49.59 201.06,-36.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;208.72&quot; y=&quot;-50.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(n + m) time where n and m are the lengths of the two strings&lt;/li&gt;
&lt;li&gt;O(|Σ|) space for arrays (26 slots), O(k) for maps (k distinct characters in both strings)&lt;/li&gt;
&lt;li&gt;Two structures must be compared — doubles the Phase 1 work&lt;/li&gt;
&lt;li&gt;Early exit possible: if lengths differ, they cannot be anagrams (check before building)&lt;/li&gt;
&lt;li&gt;Sorting both strings and comparing is also correct but O(n log n) — hashing is faster&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — comparing two structures is a Phase 2 variant&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — Phase 1 runs twice, then Phase 2 compares&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — arrays are ideal for lowercase-only anagram checks&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — different Phase 2 goal despite same Phase 1&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — compares structures instead of re-traversing&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — for known alphabets, arrays are simpler than maps&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Different lengths: immediately return false — no need to build structures&lt;/li&gt;
&lt;li&gt;Empty strings: two empty strings are anagrams (both have zero length and empty frequency maps)&lt;/li&gt;
&lt;li&gt;Case sensitivity: “Listen” and “Silent” are not anagrams by default — convert to same case first if needed&lt;/li&gt;
&lt;li&gt;Unicode characters: arrays cannot handle this — must use hash maps&lt;/li&gt;
&lt;li&gt;Whitespace and punctuation: the problem typically specifies whether to ignore these&lt;/li&gt;
&lt;li&gt;Sorting approach (O(n log n)) is simpler to code but slower — hashing is the interview-optimized answer&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>ascii-math-elimination</title>
    <link href="https://animishraa05.github.io/wiki/strings/ascii-math-elimination" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/ascii-math-elimination.md" />
    <summary>Formal Definition ASCII math elimination is the property of hash maps (like std::unordered_map) that they accept keys directly without requiring index conversion.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;ASCII math elimination is the property of hash maps (like &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt;) that they accept keys directly without requiring index conversion. Where a frequency array needs &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; to compute an array index, a hash map uses &lt;code class=&quot;notranslate&quot;&gt;freq[ch]&lt;/code&gt; directly — the character itself is the key, and the hash function handles the mapping. This eliminates the need for ASCII arithmetic entirely.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;With frequency arrays, every character must go through &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; to become an array index. This assumes lowercase ASCII contiguity, breaks for mixed case, and requires a separate reverse conversion (&lt;code class=&quot;notranslate&quot;&gt;i + &#039;a&#039;&lt;/code&gt;) for output. Hash maps bypass all of this: the character is used as-is. The hash function converts it to a bucket index internally, invisible to the programmer. This is the fundamental ergonomic advantage of hash maps over arrays.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Declare &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char, int&gt; freq&lt;/code&gt; — key type is &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt;, value type is &lt;code class=&quot;notranslate&quot;&gt;int&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To insert: &lt;code class=&quot;notranslate&quot;&gt;freq[ch]++&lt;/code&gt; — no conversion needed, the character is the key&lt;/li&gt;
&lt;li&gt;To query: &lt;code class=&quot;notranslate&quot;&gt;freq[ch]&lt;/code&gt; — same direct access&lt;/li&gt;
&lt;li&gt;Internally, the map calls &lt;code class=&quot;notranslate&quot;&gt;std::hash&amp;#x3C;char&gt;()(ch)&lt;/code&gt; to compute the bucket index&lt;/li&gt;
&lt;li&gt;The programmer never sees the hash value or bucket index — it is fully abstracted&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: ascii_elimination Pages: 1 --&gt;
&lt;svg width=&quot;324pt&quot; height=&quot;130pt&quot; viewBox=&quot;0.00 0.00 324.00 130.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 126.4)&quot;&gt;
&lt;title&gt;ascii_elimination&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-126.4 320.09,-126.4 320.09,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- ARRAY --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ARRAY&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;88.26,-41.6 0,-41.6 0,0 88.26,0 88.26,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.13&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Array:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.13&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[ch - &#039;a&#039;]&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ARROW --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ARROW&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;298.56,-41.6 210.98,-41.6 210.98,0 298.56,0 298.56,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;254.77&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;requires&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;254.77&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;ASCII math&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ARRAY&amp;#45;&amp;gt;ARROW --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ARRAY-&gt;ARROW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M88.62,-20.8C120.8,-20.8 164.87,-20.8 199.39,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;199.19,-24.3 209.19,-20.8 199.19,-17.3 199.19,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;75.48,-109.6 12.79,-109.6 12.79,-68 75.48,-68 75.48,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.13&quot; y=&quot;-93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Map:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.13&quot; y=&quot;-76.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[ch]&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HASH --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HASH&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;316.09,-118 193.46,-118 193.46,-59.6 316.09,-59.6 316.09,-118&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;254.77&quot; y=&quot;-101.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Hash function&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;254.77&quot; y=&quot;-84.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;handles mapping&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;254.77&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;(internal)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;HASH --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;HASH&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M75.92,-88.8C103.64,-88.8 145.45,-88.8 181.57,-88.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;181.56,-92.3 191.56,-88.8 181.56,-85.3 181.56,-92.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;140.86&quot; y=&quot;-109.8&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;hidden from&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;140.86&quot; y=&quot;-93&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;programmer&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_ascii_elimination Pages: 1 --&gt;
&lt;svg width=&quot;348pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 348.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_ascii_elimination&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 344.29,-205.07 344.29,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;165.37&quot; cy=&quot;-100.51&quot; rx=&quot;99.1&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;165.37&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;236.77&quot; cy=&quot;-59.01&quot; rx=&quot;70.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;236.77&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M195.65,-82.91C199.76,-80.53 203.96,-78.08 208.03,-75.71&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.34&quot; y=&quot;-82.01&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;165.21&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;165.21&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M165.34,-82.2C165.31,-68.53 165.27,-49.92 165.24,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;145.03&quot; y=&quot;-61.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;94.63&quot; cy=&quot;-142.96&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;94.63&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M136.19,-118.02C132.08,-120.49 127.85,-123.03 123.74,-125.49&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.46&quot; y=&quot;-124.46&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;237.35&quot; cy=&quot;-141.05&quot; rx=&quot;102.94&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;237.35&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Index-to-Character Conversion&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M196.32,-117.94C199.67,-119.83 203.08,-121.75 206.43,-123.64&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.87&quot; y=&quot;-112.69&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;166.81&quot; cy=&quot;-183.07&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;166.81&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M165.69,-118.83C165.93,-132.52 166.25,-151.13 166.49,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;152.33&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;93.59&quot; cy=&quot;-59.9&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;93.59&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M134.51,-83.05C131.02,-81.07 127.46,-79.06 123.97,-77.08&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;115.48&quot; y=&quot;-82.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Eliminates source of bugs: no more &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; on uppercase characters producing negative indices&lt;/li&gt;
&lt;li&gt;Works for any character type: lowercase, uppercase, digits, punctuation, Unicode&lt;/li&gt;
&lt;li&gt;No reverse conversion needed for output — the key is already the character&lt;/li&gt;
&lt;li&gt;The hash function cost is the tradeoff — internal computation replaces explicit ASCII math&lt;/li&gt;
&lt;li&gt;One less thing to think about during coding interviews — reduces cognitive load&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — the ability to use diverse key types enables this&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — maps use direct keys without conversion&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — arrays require explicit conversion; maps eliminate it&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index-to-Character Conversion&lt;/a&gt; — maps don’t need the reverse conversion either&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — arrays need known ranges; maps eliminate this assumption&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — arrays have no hashing cost but pay in conversion complexity&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;The hash function is not free — for small domains (26 lowercase letters), the conversion cost of &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; is negligible while the hash function adds measurable overhead&lt;/li&gt;
&lt;li&gt;Deleting the ASCII math does not mean deleting all constraints — the map’s hash function must handle the key type correctly (all standard types are supported in C++)&lt;/li&gt;
&lt;li&gt;For custom key types (e.g., structs), a custom hash function must be provided — ASCII math elimination only applies to built-in types&lt;/li&gt;
&lt;li&gt;The elimination is conceptual, not architectural — internally the map still converts the key to an index; it just hides this from the programmer&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>character-hashing-use-cases</title>
    <link href="https://animishraa05.github.io/wiki/strings/character-hashing-use-cases" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/character-hashing-use-cases.md" />
    <summary>Formal Definition Character hashing use cases are the set of string problems solvable by building a frequency structure (Phase 1) and then applying problem-specific retrieval logic (Phase 2).</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Character hashing use cases are the set of string problems solvable by building a frequency structure (Phase 1) and then applying problem-specific retrieval logic (Phase 2). Common patterns include finding the most frequent character, detecting anagrams, finding the first non-repeating character, checking if a string can be rearranged, and validating character-level constraints.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Character hashing is a family of problems, not a single problem. What unifies them is the Phase 1 structure (identical across all problems) and what differentiates them is the Phase 2 retrieval (unique to each problem). Mastering character hashing means recognizing which problems share Phase 1 and knowing how Phase 2 varies.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Read the problem: does it involve counting character occurrences?&lt;/li&gt;
&lt;li&gt;If yes, Phase 1 is mechanical — build the frequency structure&lt;/li&gt;
&lt;li&gt;Determine the Phase 2 pattern:
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Max/Min:&lt;/strong&gt; traverse structure, track extreme value&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order-sensitive:&lt;/strong&gt; re-traverse the original string&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comparison:&lt;/strong&gt; build two structures and compare&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constraint check:&lt;/strong&gt; verify counts satisfy a condition (e.g., palindrome rearrangement: at most one odd count)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Apply the pattern to the specific problem&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: use_cases Pages: 1 --&gt;
&lt;svg width=&quot;662pt&quot; height=&quot;144pt&quot; viewBox=&quot;0.00 0.00 662.00 144.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 140)&quot;&gt;
&lt;title&gt;use_cases&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-140 658.29,-140 658.29,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- P1 --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;415.17,-136 237.32,-136 237.32,-94.4 415.17,-94.4 415.17,-136&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;326.24&quot; y=&quot;-119.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 1:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;326.24&quot; y=&quot;-102.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Build Frequency Structure&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAX --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;140.49,-58.4 0,-58.4 0,0 140.49,0 140.49,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;70.24&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Max: Most Frequent&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;70.24&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Traverse struct,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;70.24&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;track max&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;MAX --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;MAX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M260.07,-93.98C229.4,-84.46 192.26,-72.72 151.55,-59.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;152.86,-55.89 142.27,-56.03 150.64,-62.52 152.86,-55.89&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORDER --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ORDER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;324.32,-50 158.17,-50 158.17,-8.4 324.32,-8.4 324.32,-50&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;241.24&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Order: First Non-Repeat&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;241.24&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Re-traverse string&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;ORDER --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;ORDER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M306.1,-94.29C295.17,-83.49 281.48,-69.97 269.5,-58.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;272.19,-55.86 262.61,-51.32 267.27,-60.84 272.19,-55.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COMPARE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COMPARE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;480.33,-50 342.16,-50 342.16,-8.4 480.33,-8.4 480.33,-50&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;411.24&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Compare: Anagram&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;411.24&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Build two structs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;COMPARE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;COMPARE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M346.39,-94.29C357.32,-83.49 371,-69.97 382.98,-58.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;385.22,-60.84 389.87,-51.32 380.3,-55.86 385.22,-60.84&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHECK --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHECK&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;654.29,-50 498.2,-50 498.2,-8.4 654.29,-8.4 654.29,-50&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;576.24&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Check: Palindrome&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;576.24&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;At most one odd count&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;CHECK --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;CHECK&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M386.44,-93.97C422.21,-81.95 467.77,-66.65 505.28,-54.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;506.34,-57.38 514.7,-50.88 504.11,-50.75 506.34,-57.38&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_use_cases Pages: 1 --&gt;
&lt;svg width=&quot;345pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 345.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 202.54)&quot;&gt;
&lt;title&gt;semantic_use_cases&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-202.54 340.54,-202.54 340.54,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;183.8&quot; cy=&quot;-99.11&quot; rx=&quot;126.85&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.8&quot; y=&quot;-95.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Character Hashing Use Cases&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;265.36&quot; cy=&quot;-120.62&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;265.36&quot; y=&quot;-117.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M245.2,-115.31C245.29,-115.33 245.38,-115.35 245.47,-115.38&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.83&quot; y=&quot;-107.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;142.48&quot; cy=&quot;-25.44&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.48&quot; y=&quot;-22.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M173.59,-80.9C167.23,-69.57 159.08,-55.04 152.72,-43.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;144.65&quot; y=&quot;-54.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;110.74&quot; cy=&quot;-141.11&quot; rx=&quot;101.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;110.74&quot; y=&quot;-137.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Interview Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M152.82,-116.92C148.93,-119.16 144.95,-121.44 141.08,-123.67&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;167.21&quot; y=&quot;-123&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;226.39&quot; cy=&quot;-171.9&quot; rx=&quot;68.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.39&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M194.55,-117.48C201.05,-128.6 209.32,-142.72 215.8,-153.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;232.68&quot; y=&quot;-138.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;162.26&quot; cy=&quot;-180.54&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;162.26&quot; y=&quot;-177.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M178.91,-117.59C175.39,-130.92 170.65,-148.83 167.13,-162.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;145.51&quot; y=&quot;-142.56&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON3 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON3&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;102.56&quot; cy=&quot;-76.64&quot; rx=&quot;102.56&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.56&quot; y=&quot;-73.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;First Non-Repeating Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON3 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M124.76,-82.78C124.66,-82.75 124.56,-82.73 124.47,-82.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;97.1&quot; y=&quot;-85.44&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;257.03&quot; cy=&quot;-56.82&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;257.03&quot; y=&quot;-53.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M214.86,-81.18C219.53,-78.48 224.33,-75.7 228.95,-73.04&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;235.66&quot; y=&quot;-79.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;206.1&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.1&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M188.86,-80.71C192.51,-67.43 197.42,-49.59 201.06,-36.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;181.2&quot; y=&quot;-50.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;All use cases share Phase 1 — the structure-building code is reusable across problems&lt;/li&gt;
&lt;li&gt;Phase 2 is problem-specific — changing the problem changes only the retrieval logic&lt;/li&gt;
&lt;li&gt;Problems can be categorized by Phase 2 pattern: max/min, order-sensitive, comparison, constraint&lt;/li&gt;
&lt;li&gt;The category determines data structure choice (array vs map may differ by use case)&lt;/li&gt;
&lt;li&gt;Recognition of the pattern is the skill — once Phase 2 is categorized, coding is mechanical&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — the paradigm defines the structure of all these problems&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — each use case is a specific Phase 2 strategy&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — understanding use cases enables choosing the right tool&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — a specific instance of the max/min category&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — a specific instance of the comparison category&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — a specific instance of the order-sensitive category&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Not all string problems are hashing problems — substring search, pattern matching, and edit distance use different techniques&lt;/li&gt;
&lt;li&gt;Some problems can be solved in one pass (tracking max while building frequencies) — the two-phase model is conceptual, not always sequential&lt;/li&gt;
&lt;li&gt;For palindrome rearrangement: the constraint is “at most one character has odd count” — this Phase 2 check is a simple filter&lt;/li&gt;
&lt;li&gt;For “character that appears more than n/2 times” (majority element): Boyer-Moore voting is more efficient than hashing — recognizing when NOT to hash is also important&lt;/li&gt;
&lt;li&gt;For problems with very large alphabets (Unicode), hashing is necessary but may benefit from specialized data structures (e.g., trie for prefix frequencies)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>first-non-repeating-character</title>
    <link href="https://animishraa05.github.io/wiki/strings/first-non-repeating-character" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/first-non-repeating-character.md" />
    <summary>Formal Definition The first non-repeating character in a string is the character that appears exactly once and whose first occurrence has the smallest index in the original string.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The first non-repeating character in a string is the character that appears exactly once and whose first occurrence has the smallest index in the original string. The hash-based solution uses Phase 1 to build frequencies, then re-traverses the original string in Phase 2 to find the first character with count 1.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;first_non_repeat&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mtext&gt; where &lt;/mtext&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mtext&gt; and &lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∀&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;mo&gt;&amp;#x3C;&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot;&gt;≠&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{first\_non\_repeat}(S) = S_i \text{ where } H[S_i] = 1 \text{ and } \forall j &amp;#x3C; i, H[S_j] \neq 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.06em;vertical-align:-0.31em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;first_non_repeat&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; where &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; and &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∀&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0361em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;span class=&quot;mord vbox&quot;&gt;&lt;span class=&quot;thinbox&quot;&gt;&lt;span class=&quot;rlap&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;inner&quot;&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;fix&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace nobreak&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;This problem is the first place where Phase 2 differs meaningfully from “traverse the structure.” Instead of walking the frequency array, you walk the original string a second time and check each character’s frequency. This preserves insertion order, which the frequency structure does not. It teaches that Phase 2 can re-traverse the input, not just the structure.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Phase 1: Build frequency array or hash map from the input string&lt;/li&gt;
&lt;li&gt;Phase 2: Iterate through the original string character by character&lt;/li&gt;
&lt;li&gt;For each character &lt;code class=&quot;notranslate&quot;&gt;ch&lt;/code&gt;, check &lt;code class=&quot;notranslate&quot;&gt;freq[ch - &#039;a&#039;] == 1&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;freq[ch] == 1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Return the first character where count equals 1&lt;/li&gt;
&lt;li&gt;If no character has count 1, return a sentinel (e.g., &lt;code class=&quot;notranslate&quot;&gt;&#039;\0&#039;&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;&#039;$&#039;&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: first_non_repeat Pages: 1 --&gt;
&lt;svg width=&quot;529pt&quot; height=&quot;170pt&quot; viewBox=&quot;0.00 0.00 529.00 170.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 165.6)&quot;&gt;
&lt;title&gt;first_non_repeat&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-165.6 524.54,-165.6 524.54,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- INPUT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INPUT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;68.06,-101.6 0,-101.6 0,-60 68.06,-60 68.06,-101.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;34.03&quot; y=&quot;-85&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Input:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;34.03&quot; y=&quot;-68.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;&#039;banana&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;195.58,-110 104.06,-110 104.06,-51.6 195.58,-51.6 195.58,-110&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;149.82&quot; y=&quot;-93.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 1:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;149.82&quot; y=&quot;-76.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Build Freq&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;149.82&quot; y=&quot;-59.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:3,b:1,n:2}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INPUT&amp;#45;&amp;gt;P1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INPUT-&gt;P1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M68.56,-80.8C76.04,-80.8 84.18,-80.8 92.31,-80.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;92.21,-84.3 102.21,-80.8 92.21,-77.3 92.21,-84.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- P2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;358.83,-101.6 231.58,-101.6 231.58,-60 358.83,-60 358.83,-101.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;295.21&quot; y=&quot;-85&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 2:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;295.21&quot; y=&quot;-68.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Re-traverse string&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;P2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;P2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M195.8,-80.8C203.53,-80.8 211.75,-80.8 220.02,-80.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;219.76,-84.3 229.76,-80.8 219.76,-77.3 219.76,-84.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHK_B --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHK_B&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;520.54,-161.6 394.83,-161.6 394.83,-120 520.54,-120 520.54,-161.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-145&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;&#039;b&#039; → freq=1&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-128.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;First with count 1!&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;CHK_B --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;CHK_B&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M352.79,-101.95C364.58,-106.36 377.13,-111.05 389.27,-115.59&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;387.8,-118.78 398.39,-119 390.25,-112.22 387.8,-118.78&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHK_A --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHK_A&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;502.02,-101.6 413.35,-101.6 413.35,-60 502.02,-60 502.02,-101.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-85&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;&#039;a&#039; → freq=3&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-68.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;skip&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;CHK_A --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;CHK_A&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M359.17,-80.8C373.3,-80.8 388.19,-80.8 401.95,-80.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;401.7,-84.3 411.7,-80.8 401.7,-77.3 401.7,-84.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHK_N --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHK_N&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;502.02,-41.6 413.35,-41.6 413.35,0 502.02,0 502.02,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;&#039;n&#039; → freq=2&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;457.69&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;skip&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;CHK_N --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;CHK_N&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M352.79,-59.65C368.84,-53.64 386.29,-47.12 402.22,-41.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;403.41,-44.46 411.55,-37.68 400.96,-37.9 403.41,-44.46&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_first_non_repeat Pages: 1 --&gt;
&lt;svg width=&quot;343pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 343.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_first_non_repeat&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 338.84,-203.13 338.84,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;166.44&quot; cy=&quot;-99.52&quot; rx=&quot;87.62&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;166.44&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;First Non-Repeating&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;250.05&quot; cy=&quot;-100.14&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;250.05&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M249.99,-100.14C250.01,-100.14 250.02,-100.14 250.04,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.51&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;148.52&quot; cy=&quot;-18&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.52&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M162.46,-81.43C159.51,-68.01 155.51,-49.79 152.55,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;176.01&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE3 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE3&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;91.5&quot; cy=&quot;-136.37&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;91.5&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE3 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M132.04,-116.44C129.12,-117.87 126.17,-119.33 123.27,-120.75&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;146.16&quot; y=&quot;-121.29&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;218.64&quot; cy=&quot;-164.83&quot; rx=&quot;101.81&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;218.64&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character Hashing Use Cases&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M180.98,-117.71C188.22,-126.77 196.95,-137.69 204.18,-146.74&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;212.84&quot; y=&quot;-134.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;148.48&quot; cy=&quot;-181.13&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.48&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M162.45,-117.63C159.5,-131.06 155.48,-149.3 152.51,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;184.99&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;91.22&quot; cy=&quot;-63.33&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;91.22&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M131.47,-82.7C129.79,-81.89 128.09,-81.07 126.4,-80.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.7&quot; y=&quot;-84.18&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;219.25&quot; cy=&quot;-34.8&quot; rx=&quot;98.39&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;219.25&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Array vs Hash Map Tradeoffs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M181.15,-81.49C188.47,-72.51 197.3,-61.69 204.62,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.64&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(n) Phase 1 + O(n) Phase 2 = O(n) total — two linear passes&lt;/li&gt;
&lt;li&gt;Preserves original string order in Phase 2 — this is why re-traversal is necessary&lt;/li&gt;
&lt;li&gt;The frequency structure alone cannot answer this question (it loses order information)&lt;/li&gt;
&lt;li&gt;Works with both arrays and hash maps — Phase 2 checks are O(1) in both&lt;/li&gt;
&lt;li&gt;Early termination possible — stop at the first match&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — re-traversing input is a specific Phase 2 pattern&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — the canonical example of Phase 2 differing from Phase 1&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — one implementation choice&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — same Phase 1, different Phase 2 strategy&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — another Phase 2 variant&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../map-traversal-method&quot; class=&quot;internal alias&quot; data-slug=&quot;map-traversal-method&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Traversal Method&lt;/a&gt; — re-traversal works regardless of structure type&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;All characters are repeating (e.g., “aabbcc”): no character has count 1 — must handle the no-solution case&lt;/li&gt;
&lt;li&gt;Empty string: return sentinel immediately&lt;/li&gt;
&lt;li&gt;Single character (e.g., “z”): that character is the answer — Phase 2 finds it on the first check&lt;/li&gt;
&lt;li&gt;Case sensitivity: ‘A’ and ‘a’ are different characters — the hash structure treats them separately&lt;/li&gt;
&lt;li&gt;For strings with only one unique character appearing once (e.g., “aaaabbbbccccd”): ‘d’ is the answer&lt;/li&gt;
&lt;li&gt;The naive solution without hashing is O(n²) — the hash structure reduces this to O(n)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Frequency Array vs Hash Map — Character Hashing Tradeoffs</title>
    <link href="https://animishraa05.github.io/wiki/strings/frequency-array-vs-hash-map" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/frequency-array-vs-hash-map.md" />
    <summary>Framing When solving character frequency problems, the first implementation decision is: frequency array (int freq[26]) or hash map (unordered_map&amp;lt;char,int&amp;gt;)? Both are O(1) for access, both solve the same Phase 1 problem, but they differ significantly in performance, memory, flexibility, and d...</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;framing&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Framing&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#framing&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When solving character frequency problems, the first implementation decision is: frequency array (&lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt;) or hash map (&lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char,int&gt;&lt;/code&gt;)? Both are O(1) for access, both solve the same Phase 1 problem, but they differ significantly in performance, memory, flexibility, and determinism. This synthesis compares them across the dimensions that matter in coding interviews and competitive programming.&lt;/p&gt;
&lt;h2 id=&quot;comparison&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Comparison&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#comparison&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Frequency Array&lt;/th&gt;
&lt;th&gt;Hash Map&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Access time&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;True O(1) — single CPU instruction&lt;/td&gt;
&lt;td&gt;Average O(1) — hash + possible chain walk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Worst-case&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;O(1) always&lt;/td&gt;
&lt;td&gt;O(n) with hash collisions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fixed O(|Σ|) — e.g., 104 bytes for 26 ints&lt;/td&gt;
&lt;td&gt;O(m) where m = distinct keys, but higher per-entry overhead&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Character range&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Must be known and small (e.g., a–z)&lt;/td&gt;
&lt;td&gt;Any hashable type — char, string, int, custom&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;ASCII math&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Requires &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;i + &#039;a&#039;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;None — direct key usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Iteration order&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Deterministic (0–25 index order)&lt;/td&gt;
&lt;td&gt;Non-deterministic (bucket layout)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sparse data&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Wastes iteration over empty slots&lt;/td&gt;
&lt;td&gt;Only visits present entries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stack vs heap&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Stack allocation (fast, no fragmentation)&lt;/td&gt;
&lt;td&gt;Heap allocation (slower, may fragment)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Implementation complexity&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Trivial — 1 line declaration&lt;/td&gt;
&lt;td&gt;Slightly more — need &lt;code class=&quot;notranslate&quot;&gt;#include &amp;#x3C;unordered_map&gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Rehashing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Never&lt;/td&gt;
&lt;td&gt;Amortized O(n) when load factor exceeded&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;when-to-choose-each&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;When to Choose Each&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#when-to-choose-each&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;choose-frequency-array-when&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Choose frequency array when:&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#choose-frequency-array-when&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;The problem guarantees a limited character set (e.g., “string of lowercase letters”)&lt;/li&gt;
&lt;li&gt;Maximum performance is required (time-critical section, embedded systems)&lt;/li&gt;
&lt;li&gt;Deterministic output order is needed (alphabetical by default)&lt;/li&gt;
&lt;li&gt;Memory is constrained and the domain is small&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;choose-hash-map-when&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Choose hash map when:&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#choose-hash-map-when&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;The character set is unknown or mixed (uppercase, digits, symbols)&lt;/li&gt;
&lt;li&gt;Keys are not characters (word frequencies, integer frequencies)&lt;/li&gt;
&lt;li&gt;The input is sparse over a large domain (better memory for few distinct keys)&lt;/li&gt;
&lt;li&gt;The problem involves Unicode or extended character sets&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;insights-beyond-individual-concepts&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Insights Beyond Individual Concepts&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#insights-beyond-individual-concepts&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The array-vs-map choice reveals a deeper principle in software engineering: &lt;strong&gt;the best data structure depends on the constraints of the problem, not on abstract asymptotic analysis.&lt;/strong&gt; Both are “O(1)” but the constants differ by orders of magnitude. A naive preference for maps (because they are more flexible) misses the performance advantage of arrays, and a naive preference for arrays (because they are faster) misses the flexibility advantage of maps.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;The interview answer that demonstrates mastery is the conditional one: “It depends on the character range.” This shows the candidate understands the tradeoffs rather than having memorized a rule.&lt;/p&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — the array-based approach, fastest for known domains&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — the map-based approach, most flexible&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — the precondition that makes arrays viable&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — the key advantage of maps&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Frequency Array&lt;/a&gt; — why arrays use less memory&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — why arrays are faster at the hardware level&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — the hidden cost of maps&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — one of the ergonomic benefits of maps&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../unordered-map-non-determinism&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-non-determinism&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map Non-Determinism&lt;/a&gt; — the ordering tradeoff of maps&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — the practical decision process&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hash-map-flexibility</title>
    <link href="https://animishraa05.github.io/wiki/strings/hash-map-flexibility" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/hash-map-flexibility.md" />
    <summary>Formal Definition Hash map flexibility refers to the ability of std::unordered_map (and similar hash-based associative containers) to accept any hashable type as a key — including char, int, string, long long, and custom types with a user-provided hash function.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hash map flexibility refers to the ability of &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt; (and similar hash-based associative containers) to accept any hashable type as a key — including &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;string&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;long long&lt;/code&gt;, and custom types with a user-provided hash function. This contrasts with frequency arrays, which are limited to integer-indexable domains.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;A frequency array is hardcoded to a specific domain: &lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; works only for 26 lowercase letters. A hash map, by contrast, works for any type that has a hash function. Need to count word frequencies? &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;string, int&gt;&lt;/code&gt;. Need to count frequencies of &lt;code class=&quot;notranslate&quot;&gt;long long&lt;/code&gt; IDs? &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;long long, int&gt;&lt;/code&gt;. The same data structure and the same &lt;code class=&quot;notranslate&quot;&gt;freq[key]++&lt;/code&gt; pattern works across all key types.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;C++ &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt; uses &lt;code class=&quot;notranslate&quot;&gt;std::hash&amp;#x3C;Key&gt;&lt;/code&gt; to compute a &lt;code class=&quot;notranslate&quot;&gt;size_t&lt;/code&gt; hash value for any key&lt;/li&gt;
&lt;li&gt;The C++ standard library provides specializations of &lt;code class=&quot;notranslate&quot;&gt;std::hash&lt;/code&gt; for all fundamental types&lt;/li&gt;
&lt;li&gt;At insertion, the key is stored alongside the value in the bucket&lt;/li&gt;
&lt;li&gt;On lookup, the key is hashed again, and the bucket chain is compared using &lt;code class=&quot;notranslate&quot;&gt;operator==&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For custom types, the programmer provides a &lt;code class=&quot;notranslate&quot;&gt;std::hash&lt;/code&gt; specialization&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: map_flexibility Pages: 1 --&gt;
&lt;svg width=&quot;365pt&quot; height=&quot;230pt&quot; viewBox=&quot;0.00 0.00 365.00 230.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 225.6)&quot;&gt;
&lt;title&gt;map_flexibility&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-225.6 361.11,-225.6 361.11,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;204.34,-128.8 0,-128.8 0,-92.8 204.34,-92.8 204.34,-128.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.17&quot; y=&quot;-106.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;std::unordered_map&amp;#x3C;Key, int&gt;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHAR --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHAR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;340.38,-221.6 257.07,-221.6 257.07,-180 340.38,-180 340.38,-221.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-205&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Key = char&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-188.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[&#039;a&#039;]++&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;CHAR --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;CHAR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M143.01,-129.23C172.91,-143.06 214.07,-162.1 246.43,-177.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;244.68,-180.12 255.22,-181.14 247.62,-173.76 244.68,-180.12&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- STR --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;350.61,-161.6 246.84,-161.6 246.84,-120 350.61,-120 350.61,-161.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-145&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Key = string&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-128.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[&quot;hello&quot;]++&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;STR --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;STR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.72,-126.46C215.18,-128.07 225.58,-129.68 235.43,-131.19&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;234.79,-134.64 245.21,-132.7 235.86,-127.72 234.79,-134.64&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- INT --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;338.64,-101.6 258.81,-101.6 258.81,-60 338.64,-60 338.64,-101.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-85&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Key = int&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-68.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[42]++&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;INT --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;INT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.72,-95.14C219.54,-92.86 234.23,-90.59 247.41,-88.56&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;247.72,-92.05 257.07,-87.07 246.65,-85.13 247.72,-92.05&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CUSTOM --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CUSTOM&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;357.11,-41.6 240.34,-41.6 240.34,0 357.11,0 357.11,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Key = UserType&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;298.72&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;(custom hash)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;CUSTOM --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;CUSTOM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M143.01,-92.37C171.38,-79.25 209.89,-61.43 241.4,-46.86&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;242.81,-50.06 250.42,-42.68 239.87,-43.71 242.81,-50.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_hash_map_flexibility Pages: 1 --&gt;
&lt;svg width=&quot;364pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 364.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_hash_map_flexibility&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 360.01,-203.13 360.01,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;187.23&quot; cy=&quot;-99.52&quot; rx=&quot;87.61&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;187.23&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;270.84&quot; cy=&quot;-100.14&quot; rx=&quot;85.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;270.84&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M270.78,-100.14C270.8,-100.14 270.81,-100.14 270.82,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.29&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;169.31&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;169.31&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M183.25,-81.43C180.3,-68.01 176.3,-49.79 173.34,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.03&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;112.29&quot; cy=&quot;-136.37&quot; rx=&quot;79.87&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;112.29&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M152.83,-116.44C150.67,-117.5 148.51,-118.56 146.35,-119.62&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;169.85&quot; y=&quot;-120.73&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;239.43&quot; cy=&quot;-164.83&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;239.43&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M201.77,-117.71C209.01,-126.77 217.73,-137.69 224.96,-146.74&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;240.87&quot; y=&quot;-134.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;169.27&quot; cy=&quot;-181.13&quot; rx=&quot;83.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;169.27&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Memory Efficiency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M183.24,-117.63C180.28,-131.06 176.27,-149.3 173.3,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;205.78&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;112.01&quot; cy=&quot;-63.33&quot; rx=&quot;112.01&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;112.01&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Non-Determinism&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M152.26,-82.7C150.88,-82.03 149.49,-81.37 148.11,-80.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;136.43&quot; y=&quot;-84.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;240.04&quot; cy=&quot;-34.8&quot; rx=&quot;98.39&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;240.04&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Array vs Hash Map Tradeoffs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M201.94,-81.49C209.26,-72.51 218.09,-61.69 225.41,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;227.43&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Works with any hashable type: &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;string&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;long long&lt;/code&gt;, pointers, custom structs&lt;/li&gt;
&lt;li&gt;No compile-time domain constraint — the key type is a template parameter, not a fixed size&lt;/li&gt;
&lt;li&gt;Same code pattern (&lt;code class=&quot;notranslate&quot;&gt;freq[key]++&lt;/code&gt;) regardless of key type&lt;/li&gt;
&lt;li&gt;Custom types require a custom hash function and &lt;code class=&quot;notranslate&quot;&gt;operator==&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The flexibility comes at a cost: hash computation, dynamic memory allocation, pointer indirection&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — flexibility requires hash functions, which can collide&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — maps are the concrete implementation&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — flexibility enables direct key usage&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — arrays sacrifice flexibility for the assumption&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Array&lt;/a&gt; — flexibility costs memory&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt; has no default hash for custom types — the compiler error is cryptic (“cannot convert from T to size_t”)&lt;/li&gt;
&lt;li&gt;For string keys, the hash function iterates the entire string — O(len(key)) per hash, not just O(1)&lt;/li&gt;
&lt;li&gt;Floating-point keys are problematic: NaN != NaN per IEEE 754, so lookup fails&lt;/li&gt;
&lt;li&gt;Pointer keys hash by address, not by value — two different pointers with the same value are different keys&lt;/li&gt;
&lt;li&gt;The flexibility argument cuts both ways: too flexible means type errors surface at runtime or as linker errors&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>interview-decision-framework</title>
    <link href="https://animishraa05.github.io/wiki/strings/interview-decision-framework" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/interview-decision-framework.md" />
    <summary>Formal Definition The array vs hash map decision framework is the process of choosing between int freq[26] and unordered_map&amp;lt;char,int&amp;gt; for character frequency problems based on three factors: the character range (known and small vs unknown or large), the performance requirements (speed vs flex...</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The array vs hash map decision framework is the process of choosing between &lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char,int&gt;&lt;/code&gt; for character frequency problems based on three factors: the character range (known and small vs unknown or large), the performance requirements (speed vs flexibility), and the memory constraints (fixed vs dynamic).&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When an interviewer asks “array or unordered_map?” the strong answer is not a dogmatic preference but a conditional analysis: “If the character range is fixed and small (a–z), I would use a frequency array because it is faster and uses less memory. If the range is large or unknown, I would use unordered_map because it is more flexible.” This shows understanding of the tradeoffs rather than memorization.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Check the range:&lt;/strong&gt; ask if the string is guaranteed lowercase letters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If small and known (a–z, A–Z, digits):&lt;/strong&gt; use &lt;code class=&quot;notranslate&quot;&gt;int freq[N]&lt;/code&gt; — faster, simpler, deterministic&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If large or unknown (Unicode, mixed, any char):&lt;/strong&gt; use &lt;code class=&quot;notranslate&quot;&gt;unordered_map&lt;/code&gt; — flexible, no ASCII math&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If ordered output required:&lt;/strong&gt; use array (sorted by index) or &lt;code class=&quot;notranslate&quot;&gt;std::map&lt;/code&gt; (tree-based order)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If memory-constrained with sparse input:&lt;/strong&gt; consider map (stores only what appears)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph decision_framework {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RANGE [label=&quot;Character range\nknown and small?&quot; shape=diamond]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ARR_PATH [label=&quot;Use Frequency Array\nint freq[26]\nFast, deterministic\nLow memory&quot;, fillcolor=&quot;#d4edda&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MAP_PATH [label=&quot;Use Hash Map\nunordered_map&amp;#x3C;char,int&gt;\nFlexible, no ASCII math&quot;, fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ORDER [label=&quot;Ordered output\nneeded?&quot; shape=diamond]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ORDER_ARR [label=&quot;Array (index-order) or\nstd::map (key-order)&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RANGE -&gt; ARR_PATH [label=&quot;yes\n(a-z)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RANGE -&gt; MAP_PATH [label=&quot;no\n(unknown)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ARR_PATH -&gt; ORDER [label=&quot;optional&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MAP_PATH -&gt; ORDER [style=dashed]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ORDER -&gt; ORDER_ARR [label=&quot;yes&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_decision_framework Pages: 1 --&gt;
&lt;svg width=&quot;337pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 337.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_decision_framework&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 332.79,-203.13 332.79,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;155.08&quot; cy=&quot;-99.52&quot; rx=&quot;89.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;155.08&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;238.69&quot; cy=&quot;-100.14&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;238.69&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M238.63,-100.14C238.65,-100.14 238.67,-100.14 238.68,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.15&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;137.16&quot; cy=&quot;-18&quot; rx=&quot;83.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;137.16&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Memory Efficiency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M151.1,-81.43C148.16,-68.01 144.15,-49.79 141.19,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.65&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE3 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE3&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;80.15&quot; cy=&quot;-136.37&quot; rx=&quot;70.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;80.15&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE3 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M120.68,-116.44C118.22,-117.65 115.74,-118.87 113.29,-120.08&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;135.49&quot; y=&quot;-120.96&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;207.28&quot; cy=&quot;-164.83&quot; rx=&quot;106.72&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;207.28&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;All Character Hashing Problems&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.62,-117.71C176.86,-126.77 185.59,-137.69 192.82,-146.74&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;201.48&quot; y=&quot;-134.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;137.12&quot; cy=&quot;-181.13&quot; rx=&quot;85.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;137.12&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M151.09,-117.63C148.14,-131.06 144.13,-149.3 141.16,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.64&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;79.87&quot; cy=&quot;-63.33&quot; rx=&quot;79.87&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;79.87&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M120.12,-82.7C118.12,-81.74 116.12,-80.77 114.12,-79.82&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;103.36&quot; y=&quot;-83.96&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;207.89&quot; cy=&quot;-34.8&quot; rx=&quot;112.01&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;207.89&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Non-Determinism&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.79,-81.49C177.12,-72.51 185.95,-61.69 193.26,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;195.29&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Range, speed, memory, and determinism are the four decision axes&lt;/li&gt;
&lt;li&gt;No universal “better” choice — the decision depends on the problem constraints&lt;/li&gt;
&lt;li&gt;Interviewers look for conditional reasoning, not a fixed preference&lt;/li&gt;
&lt;li&gt;The answer should be conversational: “Generally I’d use X, but if Y then Z”&lt;/li&gt;
&lt;li&gt;The framework applies beyond character hashing — it generalizes to any array-vs-hash decision&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — the range check is the first decision step&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Array&lt;/a&gt; — memory is a decision factor&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — flexibility is the deciding factor for unknown ranges&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character Hashing Use Cases&lt;/a&gt; — the framework applies to every use case&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — maps pay a collision cost that arrays avoid&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — one reason to choose maps&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;“I always use unordered_map because it’s O(1)” is a naive answer — interviewers see it as a red flag (ignores constant factors)&lt;/li&gt;
&lt;li&gt;“I always use arrays because they’re faster” misses the flexibility argument — it fails for mixed character sets&lt;/li&gt;
&lt;li&gt;The “hash map is O(1)” claim is average-case, not worst-case — a good candidate mentions this nuance&lt;/li&gt;
&lt;li&gt;For strings with only a few characters (n &amp;#x3C; 10), the overhead of any data structure may dominate — a simple loop without hashing could be faster&lt;/li&gt;
&lt;li&gt;The framework assumes you need to solve a frequency problem — if the problem doesn’t require frequencies (e.g., simple character presence check), a &lt;code class=&quot;notranslate&quot;&gt;std::set&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;bool&lt;/code&gt; array is more appropriate&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>known-range-assumption</title>
    <link href="https://animishraa05.github.io/wiki/strings/known-range-assumption" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/known-range-assumption.md" />
    <summary>Formal Definition The known range assumption states that a frequency array is only viable when the set of possible keys is known, finite, and can be mapped to contiguous integer indices.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The known range assumption states that a frequency array is only viable when the set of possible keys is known, finite, and can be mapped to contiguous integer indices. For character hashing, this means the alphabet must be predetermined (e.g., ‘a’–‘z’, ‘A’–‘Z’, or ASCII 0–127). When this assumption breaks, hash maps become necessary.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;A frequency array of size 26 works perfectly for lowercase English letters because there are exactly 26 of them and they are contiguous in ASCII. But the moment you encounter a ’#’, ‘1’, ‘A’ (uppercase), or any Unicode character, the array approach fails — either the character doesn’t fit in 26 slots, or the mapping &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; produces nonsense. The known range assumption is the invisible precondition that makes frequency arrays work, and its violation is the primary reason to switch to hash maps.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Determine the domain: what characters could possibly appear in the input?&lt;/li&gt;
&lt;li&gt;If the domain is small and contiguous (26 lowercase letters): array works&lt;/li&gt;
&lt;li&gt;If the domain is small but non-contiguous (e.g., digits + letters): array needs careful mapping&lt;/li&gt;
&lt;li&gt;If the domain is large or unknown: array is impractical or impossible&lt;/li&gt;
&lt;li&gt;The assumption is checked at problem analysis time, not at runtime&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph known_range {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CHECK [label=&quot;What characters can appear?&quot; shape=diamond]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  LOW [label=&quot;Only a-z\nArray size=26\nDirect mapping&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MIXED [label=&quot;Mixed case +\npunctuation\nArray impractical&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  UNICODE [label=&quot;Unicode / unknown\nArray impossible\nUse hash map&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PASS [label=&quot;Use freq[26]&quot; fillcolor=&quot;#d4edda&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  FAIL1 [label=&quot;Use unordered_map&quot; fillcolor=&quot;#d4edda&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CHECK -&gt; LOW [label=&quot;letters only&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CHECK -&gt; MIXED [label=&quot;multiple types&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CHECK -&gt; UNICODE [label=&quot;any character&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  LOW -&gt; PASS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MIXED -&gt; FAIL1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  UNICODE -&gt; FAIL1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_known_range Pages: 1 --&gt;
&lt;svg width=&quot;346pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 346.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_known_range&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 341.8,-205.07 341.8,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;171.78&quot; cy=&quot;-100.51&quot; rx=&quot;112.03&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;171.78&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;243.18&quot; cy=&quot;-59.01&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;243.18&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M202.06,-82.91C205.71,-80.79 209.43,-78.62 213.08,-76.5&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;189.06&quot; y=&quot;-82.41&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;171.62&quot; cy=&quot;-18&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;171.62&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M171.75,-82.2C171.72,-68.53 171.68,-49.92 171.65,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;151.44&quot; y=&quot;-61.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;101.04&quot; cy=&quot;-142.96&quot; rx=&quot;101.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.04&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Interview Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M142.19,-118.27C138.25,-120.63 134.22,-123.05 130.28,-125.41&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;115.97&quot; y=&quot;-124.54&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;243.76&quot; cy=&quot;-141.05&quot; rx=&quot;70.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;243.76&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M203.14,-118.18C206.78,-120.22 210.48,-122.31 214.09,-124.34&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;181.11&quot; y=&quot;-113.16&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;173.22&quot; cy=&quot;-183.07&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.22&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M172.1,-118.83C172.34,-132.52 172.66,-151.13 172.9,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.74&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;100&quot; cy=&quot;-59.9&quot; rx=&quot;79.87&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;100&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M140.51,-82.82C137.03,-80.85 133.5,-78.85 130.04,-76.89&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;121.51&quot; y=&quot;-82.55&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;The most commonly violated assumption in coding interviews — candidates use freq[26] without checking the character set&lt;/li&gt;
&lt;li&gt;When violated, the fix is to switch to a hash map (or expand the array to cover the full ASCII range, e.g., int freq[256])&lt;/li&gt;
&lt;li&gt;The assumption is implicit in the problem statement — “given a string of lowercase letters” explicitly guarantees it&lt;/li&gt;
&lt;li&gt;For competitive programming, problems often specify the character set to allow array-based solutions&lt;/li&gt;
&lt;li&gt;Extending the array to int freq[256] covers standard ASCII but not Unicode&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — mapping is only valid when the range is known&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — arrays depend on this assumption being true&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — this assumption is the deciding factor&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — hash maps do not require this assumption&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — both are reasons to prefer maps over arrays&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;“String of lowercase letters” guarantees the assumption — freq[26] is correct&lt;/li&gt;
&lt;li&gt;“String of characters” without qualification does NOT — use a hash map or ask for clarification&lt;/li&gt;
&lt;li&gt;Extended ASCII (128–255) breaks int freq[256] if char is signed (values become negative)&lt;/li&gt;
&lt;li&gt;Unicode characters may be multi-byte in C++ — neither freq[26] nor unordered_map&amp;#x3C;char,int&gt; handles this correctly; use unordered_map&amp;#x3C;string,int&gt; for UTF-8 strings&lt;/li&gt;
&lt;li&gt;The assumption can be partially satisfied with a translation table (mapping arbitrary characters to dense indices), but this is rarely worth the complexity&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>map-traversal-method</title>
    <link href="https://animishraa05.github.io/wiki/strings/map-traversal-method" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/map-traversal-method.md" />
    <summary>Formal Definition Hash map traversal is the process of iterating over all key-value pairs stored in an unordered_map.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hash map traversal is the process of iterating over all key-value pairs stored in an &lt;code class=&quot;notranslate&quot;&gt;unordered_map&lt;/code&gt;. In C++, this is done via range-based for loops over the map, where each element is a &lt;code class=&quot;notranslate&quot;&gt;std::pair&amp;#x3C;const Key, Value&gt;&lt;/code&gt;. Unlike array traversal which iterates a fixed range (0–25), map traversal visits only the actually inserted entries, in unspecified order.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When traversing a frequency array, you loop &lt;code class=&quot;notranslate&quot;&gt;i = 0&lt;/code&gt; to &lt;code class=&quot;notranslate&quot;&gt;25&lt;/code&gt; and check if &lt;code class=&quot;notranslate&quot;&gt;freq[i] &gt; 0&lt;/code&gt;. This visits every slot, including empty ones. When traversing a hash map, you iterate over the stored key-value pairs directly — only the characters that actually appeared. This is more efficient for sparse data but introduces non-deterministic ordering.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Obtain an iterator or range: &lt;code class=&quot;notranslate&quot;&gt;for(auto&amp;#x26; pair : freq)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Each &lt;code class=&quot;notranslate&quot;&gt;pair&lt;/code&gt; has &lt;code class=&quot;notranslate&quot;&gt;.first&lt;/code&gt; (the key) and &lt;code class=&quot;notranslate&quot;&gt;.second&lt;/code&gt; (the value)&lt;/li&gt;
&lt;li&gt;Process &lt;code class=&quot;notranslate&quot;&gt;pair.first&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;pair.second&lt;/code&gt; as needed&lt;/li&gt;
&lt;li&gt;The iteration visits every stored entry exactly once&lt;/li&gt;
&lt;li&gt;Order is determined by internal bucket layout, not by key order&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: map_traversal Pages: 1 --&gt;
&lt;svg width=&quot;556pt&quot; height=&quot;152pt&quot; viewBox=&quot;0.00 0.00 556.00 152.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 148)&quot;&gt;
&lt;title&gt;map_traversal&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-148 552.08,-148 552.08,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;114.85,-92.8 0,-92.8 0,-51.2 114.85,-51.2 114.85,-92.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.42&quot; y=&quot;-76.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;unordered_map&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.42&quot; y=&quot;-59.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{b:1, a:3, n:2}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ITER --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ITER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;301.5,-90 150.85,-90 150.85,-54 301.5,-54 301.5,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.17&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Range-based for loop&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;ITER --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;ITER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M115.34,-72C123.04,-72 131.07,-72 139.13,-72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;139.01,-75.5 149.01,-72 139.01,-68.5 139.01,-75.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAIR1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAIR1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;422.64,-144 337.5,-144 337.5,-108 422.64,-108 422.64,-144&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;380.07&quot; y=&quot;-121.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;pair: (&#039;b&#039;, 1)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ITER&amp;#45;&amp;gt;PAIR1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ITER-&gt;PAIR1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M279.02,-90.43C294.24,-95.84 310.89,-101.76 326.17,-107.19&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;324.99,-110.49 335.59,-110.54 327.34,-103.89 324.99,-110.49&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAIR2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAIR2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;422.64,-90 337.5,-90 337.5,-54 422.64,-54 422.64,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;380.07&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;pair: (&#039;a&#039;, 3)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ITER&amp;#45;&amp;gt;PAIR2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ITER-&gt;PAIR2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M301.78,-72C309.86,-72 317.95,-72 325.69,-72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;325.63,-75.5 335.63,-72 325.63,-68.5 325.63,-75.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAIR3 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAIR3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;422.64,-36 337.5,-36 337.5,0 422.64,0 422.64,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;380.07&quot; y=&quot;-13.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;pair: (&#039;n&#039;, 2)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ITER&amp;#45;&amp;gt;PAIR3 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ITER-&gt;PAIR3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M279.02,-53.57C294.24,-48.16 310.89,-42.24 326.17,-36.81&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;327.34,-40.11 335.59,-33.46 324.99,-33.51 327.34,-40.11&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PRINT --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRINT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;548.08,-101.2 458.64,-101.2 458.64,-42.8 548.08,-42.8 548.08,-101.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;503.36&quot; y=&quot;-84.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Print: &#039;b&#039; = 1&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;503.36&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Print: &#039;a&#039; = 3&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;503.36&quot; y=&quot;-51&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Print: &#039;n&#039; = 2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAIR1&amp;#45;&amp;gt;PRINT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAIR1-&gt;PRINT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M422.47,-107.57C430.67,-103.92 439.39,-100.04 447.94,-96.23&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;449.15,-99.52 456.86,-92.26 446.3,-93.13 449.15,-99.52&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAIR2&amp;#45;&amp;gt;PRINT --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAIR2-&gt;PRINT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M422.81,-72C430.63,-72 438.93,-72 447.09,-72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;446.96,-75.5 456.96,-72 446.96,-68.5 446.96,-75.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAIR3&amp;#45;&amp;gt;PRINT --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAIR3-&gt;PRINT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M422.47,-36.43C430.67,-40.08 439.39,-43.96 447.94,-47.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;446.3,-50.87 456.86,-51.74 449.15,-44.48 446.3,-50.87&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_map_traversal Pages: 1 --&gt;
&lt;svg width=&quot;344pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 344.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_map_traversal&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 340.31,-205.07 340.31,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;173.69&quot; cy=&quot;-100.51&quot; rx=&quot;119.19&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.69&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hash Map Traversal Method&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;245.08&quot; cy=&quot;-59.01&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245.08&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M204.38,-82.67C208.01,-80.56 211.71,-78.41 215.32,-76.31&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;191.35&quot; y=&quot;-82.19&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;173.52&quot; cy=&quot;-18&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.52&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M173.65,-82.2C173.63,-68.53 173.59,-49.92 173.56,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;153.34&quot; y=&quot;-61.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;102.94&quot; cy=&quot;-142.96&quot; rx=&quot;102.94&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.94&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Index-to-Character Conversion&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M144.1,-118.27C140.16,-120.63 136.12,-123.05 132.19,-125.41&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;110.63&quot; y=&quot;-124.54&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;245.67&quot; cy=&quot;-141.05&quot; rx=&quot;90.45&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245.67&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array Traversal&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M205.05,-118.18C208.39,-120.05 211.77,-121.96 215.1,-123.83&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;182.56&quot; y=&quot;-112.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;175.13&quot; cy=&quot;-183.07&quot; rx=&quot;112.01&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;175.13&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Non-Determinism&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M174.01,-118.83C174.25,-132.52 174.57,-151.13 174.81,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;160.65&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;101.91&quot; cy=&quot;-59.9&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.91&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M142.41,-82.82C139.09,-80.93 135.71,-79.02 132.4,-77.15&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;123.65&quot; y=&quot;-82.68&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Only visits entries that actually exist — no wasted iterations over empty slots&lt;/li&gt;
&lt;li&gt;Time complexity O(m) where m is distinct characters (not domain size |Σ|)&lt;/li&gt;
&lt;li&gt;No index-to-character conversion needed — the key is already the character&lt;/li&gt;
&lt;li&gt;Iteration order is unspecified and non-deterministic — do not rely on it&lt;/li&gt;
&lt;li&gt;For output, results may appear in different order across runs&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — traversal is the retrieval method for maps&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — maps have their own traversal pattern in Phase 2&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index-to-Character Conversion&lt;/a&gt; — maps don’t need conversion; arrays do&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — arrays iterate 0–25; maps iterate stored entries only&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../unordered-map-non-determinism&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-non-determinism&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map Non-Determinism&lt;/a&gt; — traversal order is unpredictable&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;For maps with many entries, iteration order changes after rehashing (when load factor exceeds threshold)&lt;/li&gt;
&lt;li&gt;Do NOT modify the map while iterating (adding/removing entries) — this causes undefined behavior&lt;/li&gt;
&lt;li&gt;Using &lt;code class=&quot;notranslate&quot;&gt;auto&lt;/code&gt; instead of &lt;code class=&quot;notranslate&quot;&gt;auto&amp;#x26;&lt;/code&gt; copies each pair — O(n) extra work for large maps&lt;/li&gt;
&lt;li&gt;For ordered output, copy to a vector and sort, or use &lt;code class=&quot;notranslate&quot;&gt;std::map&lt;/code&gt; (which has O(log n) operations)&lt;/li&gt;
&lt;li&gt;The loop variable &lt;code class=&quot;notranslate&quot;&gt;.first&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;.second&lt;/code&gt; can be confusing to beginners — use structured bindings: &lt;code class=&quot;notranslate&quot;&gt;auto&amp;#x26; [key, value] : freq&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>memory-efficiency-array</title>
    <link href="https://animishraa05.github.io/wiki/strings/memory-efficiency-array" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/memory-efficiency-array.md" />
    <summary>Formal Definition A frequency array has memory proportional to the domain size (O(|\Sigma|)) regardless of the input size, with zero per-entry overhead beyond the integer storage itself.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;A frequency array has memory proportional to the domain size (&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;O(|\Sigma|)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣Σ∣&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;) regardless of the input size, with zero per-entry overhead beyond the integer storage itself. For lowercase letters, &lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; occupies exactly &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;26&lt;/mn&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;104&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;26 \times 4 = 104&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7278em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;×&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;104&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; bytes — a fixed cost that does not grow with the string length.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The memory efficiency of a frequency array comes from two properties: it is a fixed-size allocation determined at compile time, and it stores data in a contiguous block with no per-element metadata, no hash table buckets, no linked list pointers, and no key duplication. A hash map, by contrast, stores the key alongside each value, plus internal hash table structures. For small domains, the array’s memory advantage is significant.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; allocates 26 × sizeof(int) bytes on the stack (or in static memory)&lt;/li&gt;
&lt;li&gt;Each slot is accessed via base+offset addressing — no pointers, no indirection&lt;/li&gt;
&lt;li&gt;The entire array fits in a single CPU cache line (typically 64 bytes × 2 for 104 bytes)&lt;/li&gt;
&lt;li&gt;No memory is wasted on empty slots — every slot is exactly sized for one integer&lt;/li&gt;
&lt;li&gt;No heap allocation, no reallocation, no memory fragmentation&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext&gt;Memory&lt;/mtext&gt;&lt;mtext&gt;array&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mtext&gt;sizeof&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;element&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Memory}_{\text{array}} = |\Sigma| \times \text{sizeof}(\text{element})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0636em;vertical-align:-0.3802em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Memory&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.0573em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;array&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3802em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣Σ∣&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;×&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;sizeof&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;element&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext&gt;Memory&lt;/mtext&gt;&lt;mtext&gt;array&lt;/mtext&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;26&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;26&lt;/mn&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;104&lt;/mn&gt;&lt;mtext&gt; bytes&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Memory}_{\text{array}}(26) = 26 \times 4 = 104 \text{ bytes}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1302em;vertical-align:-0.3802em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Memory&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.0573em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;array&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3802em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7278em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;×&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;104&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; bytes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mtext&gt;Memory&lt;/mtext&gt;&lt;mtext&gt;map&lt;/mtext&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;sizeof&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;key&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mtext&gt;sizeof&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;value&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mtext&gt;overhead&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Memory}_{\text{map}} = m \times (\text{sizeof}(\text{key}) + \text{sizeof}(\text{value}) + \text{overhead})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0636em;vertical-align:-0.3802em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Memory&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.0573em;&quot;&gt;&lt;span style=&quot;top:-2.4559em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;map&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3802em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;×&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;sizeof&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;key&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;sizeof&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;overhead&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;m&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the number of distinct characters and overhead includes hash table bucket, pointer chain, and alignment padding.&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: memory_layout Pages: 1 --&gt;
&lt;svg width=&quot;356pt&quot; height=&quot;598pt&quot; viewBox=&quot;0.00 0.00 356.00 598.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 594.2)&quot;&gt;
&lt;title&gt;memory_layout&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-594.2 351.73,-594.2 351.73,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- ARRAY --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ARRAY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;25.69,-0.5 25.69,-422.1 93.05,-422.1 93.05,-0.5 25.69,-0.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-405.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[26]:&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-397.3 93.05,-397.3&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-380.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;3&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-372.5 93.05,-372.5&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-355.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;1&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-347.7 93.05,-347.7&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-331.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-322.9 93.05,-322.9&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-306.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-298.1 93.05,-298.1&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-281.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-273.3 93.05,-273.3&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-256.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-248.5 93.05,-248.5&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-231.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-223.7 93.05,-223.7&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-207.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-198.9 93.05,-198.9&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-182.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-174.1 93.05,-174.1&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-157.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-149.3 93.05,-149.3&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-132.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-124.5 93.05,-124.5&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-107.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-99.7 93.05,-99.7&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-83.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;0&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-74.9 93.05,-74.9&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-58.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;2&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-50.1 93.05,-50.1&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-33.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;...&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;25.69,-25.3 93.05,-25.3&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-8.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt; &lt;/text&gt;
&lt;/g&gt;
&lt;!-- CACHE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CACHE&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;227.46,-190.5 227.46,-232.1 347.73,-232.1 347.73,-190.5 227.46,-190.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;287.6&quot; y=&quot;-215.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;CPU Cache Line&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;287.6&quot; y=&quot;-198.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;(64 bytes)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ARRAY&amp;#45;&amp;gt;CACHE --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ARRAY-&gt;CACHE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M93.26,-211.3C125.3,-211.3 175.02,-211.3 216.02,-211.3&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;215.82,-214.8 225.82,-211.3 215.82,-207.8 215.82,-214.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.1&quot; y=&quot;-215.5&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;fits in 2 lines&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;0,-440.9 0,-589.7 118.74,-589.7 118.74,-440.9 0,-440.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-573.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;unordered_map:&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;0,-564.9 118.74,-564.9&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-548.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;bucket ptr&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;0,-540.1 118.74,-540.1&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-523.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;key&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;0,-515.3 118.74,-515.3&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-498.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;value&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;0,-490.5 118.74,-490.5&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-473.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;next&lt;/text&gt;
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;0,-465.7 118.74,-465.7&quot;&gt;&lt;/polyline&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.37&quot; y=&quot;-449.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;...&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_memory_efficiency Pages: 1 --&gt;
&lt;svg width=&quot;337pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 337.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_memory_efficiency&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 333.22,-203.13 333.22,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;175.97&quot; cy=&quot;-99.52&quot; rx=&quot;109.59&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;175.97&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Memory Efficiency (Array)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;259.58&quot; cy=&quot;-100.14&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;259.58&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M259.52,-100.14C259.54,-100.14 259.56,-100.14 259.57,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;241.04&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;158.05&quot; cy=&quot;-18&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.05&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M171.99,-81.43C169.04,-68.01 165.04,-49.79 162.08,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;187.3&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;101.04&quot; cy=&quot;-136.37&quot; rx=&quot;101.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.04&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Interview Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M140.7,-116.87C139.18,-117.61 137.66,-118.36 136.14,-119.11&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;118.15&quot; y=&quot;-120.69&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;228.17&quot; cy=&quot;-164.83&quot; rx=&quot;85.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;228.17&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M190.51,-117.71C197.75,-126.77 206.48,-137.69 213.71,-146.74&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;229.62&quot; y=&quot;-134.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON2&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;158.01&quot; cy=&quot;-181.13&quot; rx=&quot;70.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.01&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M171.98,-117.63C169.03,-131.06 165.01,-149.3 162.05,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.51&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;100.76&quot; cy=&quot;-63.33&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;100.76&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M139.69,-82.06C138.48,-81.48 137.28,-80.91 136.08,-80.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;151.64&quot; y=&quot;-83.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;228.78&quot; cy=&quot;-34.8&quot; rx=&quot;98.39&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;228.78&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Array vs Hash Map Tradeoffs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M190.68,-81.49C198.01,-72.51 206.84,-61.69 214.15,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;216.17&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Fixed 104 bytes for lowercase English — independent of string length&lt;/li&gt;
&lt;li&gt;Zero per-entry overhead — just the integer value itself&lt;/li&gt;
&lt;li&gt;Stack allocation — no heap fragmentation, no pointer chasing&lt;/li&gt;
&lt;li&gt;Cache-friendly — sequential access pattern leverages spatial locality&lt;/li&gt;
&lt;li&gt;Hash maps typically use 3–5× more memory per entry due to key storage, bucket array, and pointer chains&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — contiguous memory enables efficient addressing&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — memory efficiency is a key advantage of arrays&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — memory is a decision factor&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — maps pay for collision resolution structures&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — flexibility comes with memory cost&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;For very large alphabets (e.g., Unicode with 1M+ code points), the array becomes impractical — int freq[1,114,112] is over 4 MB&lt;/li&gt;
&lt;li&gt;Stack allocation for large arrays causes stack overflow — use heap allocation (std::vector) instead&lt;/li&gt;
&lt;li&gt;If only 3 out of 26 characters appear, the array still uses all 104 bytes — no savings from sparsity&lt;/li&gt;
&lt;li&gt;The memory advantage reverses for sparse data over a large domain: a hash map storing only the 3 appearing characters uses less memory than a full array of the domain&lt;/li&gt;
&lt;li&gt;For multibyte encodings (UTF-8), neither freq[26] nor a simple char map works — the key type must handle variable-length sequences&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>most-frequent-character</title>
    <link href="https://animishraa05.github.io/wiki/strings/most-frequent-character" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/most-frequent-character.md" />
    <summary>Formal Definition Finding the most frequent character in a string using hashing means traversing the frequency structure (array or hash map) after Phase 1 to identify the key-value pair with the maximum count.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Finding the most frequent character in a string using hashing means traversing the frequency structure (array or hash map) after Phase 1 to identify the key-value pair with the maximum count. For ties, any character with the maximum count is acceptable unless otherwise specified.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;most_frequent&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;arg&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;msub&gt;&lt;mrow&gt;&lt;mi&gt;max&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mtext&gt;keys&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{most\_frequent}(S) = \arg\max_{c \in \text{keys}(H)} H[c]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.06em;vertical-align:-0.31em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;most_frequent&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1052em;vertical-align:-0.3552em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;ar&lt;span style=&quot;margin-right:0.0139em;&quot;&gt;g&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3448em;&quot;&gt;&lt;span style=&quot;top:-2.5198em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mrel mtight&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mord text mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;keys&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen mtight&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mclose mtight&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3552em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;H&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the hash structure built in Phase 1.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;After building a frequency array or hash map, the data is stored but not interpreted. Finding the most frequent character is the simplest Phase 2 operation: walk through every entry in the structure, compare counts, and track the current maximum. This teaches the core pattern that Phase 1 is mechanical and Phase 2 is analytical.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Complete Phase 1 — build &lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char,int&gt; freq&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Initialize tracking variables: &lt;code class=&quot;notranslate&quot;&gt;char maxChar = &#039; &#039;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;int maxCount = 0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Traverse the frequency structure:
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;For array:&lt;/strong&gt; loop &lt;code class=&quot;notranslate&quot;&gt;i = 0&lt;/code&gt; to &lt;code class=&quot;notranslate&quot;&gt;25&lt;/code&gt;, if &lt;code class=&quot;notranslate&quot;&gt;freq[i] &gt; maxCount&lt;/code&gt;, update &lt;code class=&quot;notranslate&quot;&gt;maxCount = freq[i]&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;maxChar = i + &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;For map:&lt;/strong&gt; iterate key-value pairs, if &lt;code class=&quot;notranslate&quot;&gt;pair.second &gt; maxCount&lt;/code&gt;, update&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;After traversal, &lt;code class=&quot;notranslate&quot;&gt;maxChar&lt;/code&gt; holds the most frequent character&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: most_frequent Pages: 1 --&gt;
&lt;svg width=&quot;1106pt&quot; height=&quot;114pt&quot; viewBox=&quot;0.00 0.00 1106.00 114.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 110)&quot;&gt;
&lt;title&gt;most_frequent&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-110 1102.25,-110 1102.25,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- STRUCT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STRUCT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;105.48,-50 0,-50 0,-8.4 105.48,-8.4 105.48,-50&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;52.74&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Freq Structure&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;52.74&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;a:3, b:1, n:2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INIT --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INIT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;246.02,-50 142.48,-50 142.48,-8.4 246.02,-8.4 246.02,-50&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;194.25&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxCount = 0&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;194.25&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxChar = &#039;&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STRUCT&amp;#45;&amp;gt;INIT --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STRUCT-&gt;INIT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.69,-29.2C113.89,-29.2 122.44,-29.2 130.85,-29.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;130.67,-32.7 140.67,-29.2 130.67,-25.7 130.67,-32.7&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHECK --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHECK&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;418.19,-47.2 283.02,-29.2 418.19,-11.2 553.36,-29.2 418.19,-47.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;418.19&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[i] &gt; maxCount?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INIT&amp;#45;&amp;gt;CHECK --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INIT-&gt;CHECK&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M246.45,-29.2C253.33,-29.2 260.64,-29.2 268.23,-29.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;268.01,-32.7 278.01,-29.2 268.01,-25.7 268.01,-32.7&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- UPDATE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;UPDATE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;738.79,-106 608.02,-106 608.02,-64.4 738.79,-64.4 738.79,-106&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;673.41&quot; y=&quot;-89.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxCount = freq[i]&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;673.41&quot; y=&quot;-72.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxChar = ch&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHECK&amp;#45;&amp;gt;UPDATE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHECK-&gt;UPDATE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M470.74,-40.6C506.95,-48.61 555.99,-59.45 596.65,-68.45&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;595.88,-71.86 606.4,-70.6 597.39,-65.02 595.88,-71.86&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;580.69&quot; y=&quot;-69.69&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;yes&lt;/text&gt;
&lt;/g&gt;
&lt;!-- NEXT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;NEXT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;853.64,-47.2 775.79,-29.2 853.64,-11.2 931.48,-29.2 853.64,-47.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;853.64&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Next entry&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHECK&amp;#45;&amp;gt;NEXT --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHECK-&gt;NEXT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M556.93,-29.2C624.12,-29.2 703.04,-29.2 762.44,-29.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;762.16,-32.7 772.16,-29.2 762.16,-25.7 762.16,-32.7&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;673.41&quot; y=&quot;-33.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;no&lt;/text&gt;
&lt;/g&gt;
&lt;!-- UPDATE&amp;#45;&amp;gt;NEXT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;UPDATE-&gt;NEXT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M739.26,-64.82C762.37,-57.56 787.85,-49.56 808.79,-42.98&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;809.66,-46.37 818.15,-40.04 807.56,-39.69 809.66,-46.37&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- NEXT&amp;#45;&amp;gt;CHECK --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;NEXT-&gt;CHECK&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M813.1,-20.16C791.31,-15.64 763.71,-10.66 738.79,-8.4 654.95,-0.8 558.48,-9.47 493.66,-17.82&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;493.29,-14.34 483.83,-19.12 494.2,-21.28 493.29,-14.34&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;673.41&quot; y=&quot;-12.6&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;more&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DONE --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DONE&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;1098.25,-58.4 994.7,-58.4 994.7,0 1098.25,0 1098.25,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1046.47&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Result:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1046.47&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxChar = &#039;a&#039;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1046.47&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;maxCount = 3&lt;/text&gt;
&lt;/g&gt;
&lt;!-- NEXT&amp;#45;&amp;gt;DONE --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;NEXT-&gt;DONE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M933.64,-29.2C950.14,-29.2 967.31,-29.2 983.11,-29.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;982.83,-32.7 992.83,-29.2 982.83,-25.7 982.83,-32.7&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;963.09&quot; y=&quot;-33.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;done&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_most_frequent Pages: 1 --&gt;
&lt;svg width=&quot;358pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 358.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 202.54)&quot;&gt;
&lt;title&gt;semantic_most_frequent&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-202.54 354.16,-202.54 354.16,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;183.8&quot; cy=&quot;-99.11&quot; rx=&quot;106.27&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.8&quot; y=&quot;-95.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;265.36&quot; cy=&quot;-120.62&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;265.36&quot; y=&quot;-117.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M242.21,-114.52C242.31,-114.54 242.41,-114.57 242.52,-114.6&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;223.86&quot; y=&quot;-117.26&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;142.48&quot; cy=&quot;-25.44&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.48&quot; y=&quot;-22.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M173.59,-80.9C167.23,-69.57 159.08,-55.04 152.72,-43.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;144.65&quot; y=&quot;-54.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE3 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE3&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;110.74&quot; cy=&quot;-141.11&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;110.74&quot; y=&quot;-137.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE3 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M153.24,-116.68C148.55,-119.38 143.72,-122.15 139.08,-124.82&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.67&quot; y=&quot;-123.45&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;226.39&quot; cy=&quot;-171.9&quot; rx=&quot;101.81&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.39&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character Hashing Use Cases&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M194.55,-117.48C201,-128.52 209.19,-142.51 215.65,-153.54&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;225.36&quot; y=&quot;-138.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;162.26&quot; cy=&quot;-180.54&quot; rx=&quot;101.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;162.26&quot; y=&quot;-177.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Interview Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M178.91,-117.59C175.39,-130.92 170.65,-148.83 167.13,-162.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;193.29&quot; y=&quot;-142.56&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;102.56&quot; cy=&quot;-76.64&quot; rx=&quot;102.56&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.56&quot; y=&quot;-73.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;First Non-Repeating Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M127.38,-83.5C127.27,-83.47 127.16,-83.44 127.05,-83.41&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;99.71&quot; y=&quot;-75.36&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;257.03&quot; cy=&quot;-56.82&quot; rx=&quot;87.82&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;257.03&quot; y=&quot;-53.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Index-to-Char Conversion&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M214.43,-81.42C218.66,-78.98 223.01,-76.47 227.22,-74.03&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.59&quot; y=&quot;-80.43&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;206.1&quot; cy=&quot;-18&quot; rx=&quot;98.39&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.1&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Array vs Hash Map Tradeoffs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M188.86,-80.71C192.51,-67.43 197.42,-49.59 201.06,-36.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;181.2&quot; y=&quot;-50.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Given hash structure &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo&gt;:&lt;/mo&gt;&lt;mtext&gt;Key&lt;/mtext&gt;&lt;mo&gt;→&lt;/mo&gt;&lt;mi mathvariant=&quot;double-struck&quot;&gt;N&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;H: \text{Key} \to \mathbb{N}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;→&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6889em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathbb&quot;&gt;N&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;result&lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mrow&gt;&lt;mi&gt;max&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{result} = \max_{(k,v) \in H} v&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;result&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7858em;vertical-align:-0.3552em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3448em;&quot;&gt;&lt;span style=&quot;top:-2.5198em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mopen mtight&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0315em;&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;mpunct mtight&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;mclose mtight&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mrel mtight&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3552em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;v&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;character&lt;/mtext&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mtext&gt; where &lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;max&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{character} = k \text{ where } (k, \max) \in H&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;character&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0315em;&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; where &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0315em;&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(n) Phase 1 (traverse string) + O(|Σ|) or O(m) Phase 2 (traverse structure) = overall O(n)&lt;/li&gt;
&lt;li&gt;Only a constant amount of extra space needed (two tracking variables)&lt;/li&gt;
&lt;li&gt;Works identically for both frequency arrays and hash maps&lt;/li&gt;
&lt;li&gt;For ties, returns the first maximum encountered — order-dependent&lt;/li&gt;
&lt;li&gt;Cannot be solved correctly without Phase 1 — the hash structure is essential&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — traversing structure for max is a Phase 2 pattern&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — follows the store-then-query pattern&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — one implementation choice for Phase 1&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character Hashing Use Cases&lt;/a&gt; — a canonical example problem&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — same Phase 1, different Phase 2 traversal&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index-to-Character Conversion&lt;/a&gt; — needed to convert the max index back to a character&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Empty string: Phase 1 produces an empty structure — handle separately or initialize maxCount to 0 and return a sentinel&lt;/li&gt;
&lt;li&gt;Ties: the problem may expect any character — clarify with the interviewer whether the first, last, or lexicographically smallest should be returned&lt;/li&gt;
&lt;li&gt;Single character string: the answer is that character — works correctly in both structures&lt;/li&gt;
&lt;li&gt;All characters appear once: the first character in traversal order wins (for maps, this is non-deterministic)&lt;/li&gt;
&lt;li&gt;For hash maps, if tied characters exist, the result depends on internal bucket order — non-deterministic across runs&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Strings — Map of Content</title>
    <link href="https://animishraa05.github.io/wiki/strings/strings-moc" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/strings-moc.md" />
    <summary> Map of Content for all pages derived from Strings (Character Hashing in C++).</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;blockquote&gt;
&lt;p dir=&quot;auto&quot;&gt;Map of Content for all pages derived from &lt;a href=&quot;../../strings-summary&quot; class=&quot;internal alias&quot; data-slug=&quot;strings-summary&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Strings (Character Hashing in C++)&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id=&quot;core-paradigm&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Paradigm&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-paradigm&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — the fundamental model&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hashing-store-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-store-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Store Phase (Phase 1)&lt;/a&gt; — building the frequency structure&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase (Phase 2)&lt;/a&gt; — querying the structure&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;data-structures&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Data Structures&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#data-structures&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — fixed-size array for known domains&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — hash map for flexible domains&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — hardware-level O(1) array indexing&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — performance cost of hash maps&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;mappings--conversions&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mappings &amp;#x26; Conversions&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mappings--conversions&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index-to-Character Conversion&lt;/a&gt; — &lt;code class=&quot;notranslate&quot;&gt;i + &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — maps remove the need for ASCII math&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;key-properties--assumptions&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties &amp;#x26; Assumptions&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties--assumptions&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — when arrays work&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Frequency Array&lt;/a&gt; — fixed 104-byte footprint&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — any hashable key type&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../map-traversal-method&quot; class=&quot;internal alias&quot; data-slug=&quot;map-traversal-method&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Traversal Method&lt;/a&gt; — iterating key-value pairs&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../unordered-map-non-determinism&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-non-determinism&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map Non-Determinism&lt;/a&gt; — unspecified iteration order&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;problem-patterns-phase-2&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Problem Patterns (Phase 2)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#problem-patterns-phase-2&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character via Hashing&lt;/a&gt; — traverse for max&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character via Hashing&lt;/a&gt; — re-traverse input&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection via Hashing&lt;/a&gt; — compare two structures&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character Hashing Use Cases&lt;/a&gt; — catalog of all patterns&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;decision-making&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Decision Making&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#decision-making&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — choosing the right tool&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../frequency-array-vs-hash-map&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array-vs-hash-map&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array vs Hash Map&lt;/a&gt; — detailed comparison&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../two-phase-hashing-patterns&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing-patterns&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Patterns&lt;/a&gt; — catalog of Phase 2 strategies&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Two-Phase Hashing Patterns — A Catalog of Phase 2 Strategies</title>
    <link href="https://animishraa05.github.io/wiki/strings/two-phase-hashing-patterns" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/two-phase-hashing-patterns.md" />
    <summary>Framing The two-phase hashing paradigm separates frequency problems into Phase 1 (store) and Phase 2 (use).</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;framing&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Framing&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#framing&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The two-phase hashing paradigm separates frequency problems into Phase 1 (store) and Phase 2 (use). While Phase 1 is nearly identical across all problems, Phase 2 varies based on what the problem asks for. This deep-dive catalogs the distinct Phase 2 patterns, showing how the same data structure supports fundamentally different queries.&lt;/p&gt;
&lt;h2 id=&quot;the-five-phase-2-patterns&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Five Phase 2 Patterns&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-five-phase-2-patterns&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;pattern-1-traverse-for-extremum-most-frequent-character&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Pattern 1: Traverse for Extremum (Most Frequent Character)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#pattern-1-traverse-for-extremum-most-frequent-character&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p dir=&quot;auto&quot;&gt;Walk the entire structure, tracking a running maximum. For arrays, this means iterating indices 0–25. For maps, iterating key-value pairs.&lt;/p&gt;
&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code class=&quot;notranslate&quot;&gt;maxCount = 0
maxChar = &#039;&#039;
for each entry (key, count) in structure:
    if count &gt; maxCount:
        maxCount = count
        maxChar = key
return maxChar
&lt;/code&gt;&lt;/pre&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;Used by:&lt;/strong&gt; most frequent character, least frequent character, character with maximum occurrences&lt;/p&gt;
&lt;h3 id=&quot;pattern-2-re-traverse-input-for-order-first-non-repeating-character&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Pattern 2: Re-traverse Input for Order (First Non-Repeating Character)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#pattern-2-re-traverse-input-for-order-first-non-repeating-character&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p dir=&quot;auto&quot;&gt;Iterate the original string a second time and check each character’s frequency in the structure. This preserves the original insertion order.&lt;/p&gt;
&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code class=&quot;notranslate&quot;&gt;for each ch in originalString:
    if freq[ch] == 1:
        return ch
return sentinel
&lt;/code&gt;&lt;/pre&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;Used by:&lt;/strong&gt; first non-repeating character, first repeating character, first character with frequency K&lt;/p&gt;
&lt;h3 id=&quot;pattern-3-compare-two-structures-anagram-detection&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Pattern 3: Compare Two Structures (Anagram Detection)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#pattern-3-compare-two-structures-anagram-detection&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p dir=&quot;auto&quot;&gt;Build two frequency structures (Phase 1 for each input), then compare entry by entry. For arrays this means element-wise comparison; for maps, checking all key-value pairs match.&lt;/p&gt;
&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code class=&quot;notranslate&quot;&gt;if len(S1) != len(S2): return false
freq1 = build(S1)
freq2 = build(S2)
return freq1 == freq2
&lt;/code&gt;&lt;/pre&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;Used by:&lt;/strong&gt; anagram detection, string permutation check, isomorphic strings&lt;/p&gt;
&lt;h3 id=&quot;pattern-4-constraint-check-palindrome-rearrangement&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Pattern 4: Constraint Check (Palindrome Rearrangement)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#pattern-4-constraint-check-palindrome-rearrangement&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p dir=&quot;auto&quot;&gt;Check if frequencies satisfy a condition without finding a specific character. The condition often involves the parity of counts.&lt;/p&gt;
&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code class=&quot;notranslate&quot;&gt;oddCount = 0
for each count:
    if count % 2 == 1:
        oddCount++
return oddCount &amp;#x3C;= 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;Used by:&lt;/strong&gt; palindrome rearrangement possible? string can be made palindrome, at most K swaps&lt;/p&gt;
&lt;h3 id=&quot;pattern-5-structure-comparison-with-difference-edit-distance-for-anagrams&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Pattern 5: Structure Comparison with Difference (Edit Distance for Anagrams)&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#pattern-5-structure-comparison-with-difference-edit-distance-for-anagrams&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p dir=&quot;auto&quot;&gt;Compute the difference between two frequency structures to determine how many changes are needed to make two strings anagrams.&lt;/p&gt;
&lt;pre class=&quot;notranslate&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code class=&quot;notranslate&quot;&gt;diff = 0
for i in 0..25:
    diff += abs(freq1[i] - freq2[i])
return diff / 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;strong&gt;Used by:&lt;/strong&gt; minimum steps to make anagram, character deletions to make strings equal&lt;/p&gt;
&lt;h2 id=&quot;insights&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Insights&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#insights&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The key insight is that &lt;strong&gt;Phase 1 is invariant across all these problems.&lt;/strong&gt; You can write the frequency-building code once and reuse it. The only thing that changes is the Phase 2 loop. This is why recognizing the pattern is more important than memorizing the solution: once you identify which Phase 2 pattern a problem uses, you can write the solution from first principles.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;A second insight is that &lt;strong&gt;some problems combine multiple patterns.&lt;/strong&gt; For example, finding the most frequent character in the first string that also appears at least twice in the second string: Pattern 3 (compare) + Pattern 1 (extremum).&lt;/p&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — the overarching model&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hashing-store-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-store-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Store Phase&lt;/a&gt; — Phase 1, invariant across patterns&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — Phase 2, the pattern catalog&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — implements Pattern 1&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — implements Pattern 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — implements Pattern 3&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character Hashing Use Cases&lt;/a&gt; — the full set of problems&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — the structure used in Phase 1&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency Counting&lt;/a&gt; — alternative Phase 1 structure&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>unordered-map-non-determinism</title>
    <link href="https://animishraa05.github.io/wiki/strings/unordered-map-non-determinism" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/unordered-map-non-determinism.md" />
    <summary>Formal Definition Unordered map non-determinism refers to the property that std::unordered_map does not guarantee any specific iteration order, and the order may change between program runs, library versions, or after rehashing.</summary>
    <published>2026-07-05T00:00:00.000Z</published>
    <updated>2026-07-05T00:00:00.000Z</updated>
    <publishedTime>Jul 05, 2026</publishedTime>
    <updatedTime>Jul 05, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Unordered map non-determinism refers to the property that &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt; does not guarantee any specific iteration order, and the order may change between program runs, library versions, or after rehashing. The iteration order is determined by the internal bucket layout, which depends on the hash function, load factor, and insertion history.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When you iterate a frequency array (0–25), the order is always a, b, c, …, z. When you iterate an &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char, int&gt;&lt;/code&gt;, the order depends on how the hash function distributes keys across buckets. For “banana”, you might get &lt;code class=&quot;notranslate&quot;&gt;{a:3, b:1, n:2}&lt;/code&gt; in one run and &lt;code class=&quot;notranslate&quot;&gt;{b:1, n:2, a:3}&lt;/code&gt; in another. This matters when output order is part of the problem specification or test cases.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Each key is hashed to a bucket index: &lt;code class=&quot;notranslate&quot;&gt;bucket = hash(key) % bucket_count&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Insertion order within a bucket is the order of insertion into that bucket’s chain&lt;/li&gt;
&lt;li&gt;Iteration visits buckets in order of bucket index, then entries within each bucket&lt;/li&gt;
&lt;li&gt;When the map rehashes (grows), all entries are rehashed — bucket assignments change&lt;/li&gt;
&lt;li&gt;The hash function may use a random seed (SSO/ASLR) to prevent hash DoS attacks, making order vary across executions&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph non_determinism {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=LR&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC [label=&quot;Source:\n{a:3, b:1, n:2}&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN1 [label=&quot;Run 1:\na=3, b=1, n=2&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN2 [label=&quot;Run 2:\nb=1, n=2, a=3&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN3 [label=&quot;Run 3:\nn=2, a=3, b=1&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; RUN1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; RUN2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; RUN3&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;graph semantic_non_determinism {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  layout=neato&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=ellipse fontname=&quot;Helvetica&quot; fontsize=11 style=filled]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=9]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS [label=&quot;Unordered Map Non-Determinism&quot; fillcolor=&quot;#ffd700&quot; fontsize=13 style=&quot;filled,bold&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PRE1 [label=&quot;Hash Collision Overhead&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PRE2 [label=&quot;Hash Map Flexibility&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  OUT1 [label=&quot;Map Traversal Method&quot; fillcolor=&quot;#d4edda]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CON1 [label=&quot;Frequency Array&quot; fillcolor=&quot;#ffe5cc&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REL1 [label=&quot;Interview Decision Framework&quot; fillcolor=&quot;#f0f0f0&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REL2 [label=&quot;Array vs Hash Map Tradeoffs&quot; fillcolor=&quot;#f0f0f0&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- PRE1 [label=&quot;built from&quot; style=dashed]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- PRE2 [label=&quot;built from&quot; style=dashed]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- OUT1 [label=&quot;builds into&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- CON1 [label=&quot;contrasts with&quot; style=dotted]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- REL1 [label=&quot;related&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- REL2 [label=&quot;related&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Iteration order is not a bug — it is a design feature (performance over determinism)&lt;/li&gt;
&lt;li&gt;Order can change between: compilers, standard library versions, program runs, and before/after rehashing&lt;/li&gt;
&lt;li&gt;Frequency arrays guarantee deterministic, sorted-by-index order&lt;/li&gt;
&lt;li&gt;If order matters, copy to a vector and sort, or use &lt;code class=&quot;notranslate&quot;&gt;std::map&lt;/code&gt; (tree-based, ordered)&lt;/li&gt;
&lt;li&gt;Non-determinism affects output formatting, not correctness of frequency values&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — bucket layout drives iteration order&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — the flexibility tradeoff includes non-determinism&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../map-traversal-method&quot; class=&quot;internal alias&quot; data-slug=&quot;map-traversal-method&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Traversal Method&lt;/a&gt; — traversal must account for unspecified order&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — arrays give predictable, index-based order&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../interview-decision-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;interview-decision-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Array vs Hash Map Decision Framework&lt;/a&gt; — determinism is a decision factor&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Automated test suites that compare output as strings will fail if they expect a specific order from unordered_map&lt;/li&gt;
&lt;li&gt;Using &lt;code class=&quot;notranslate&quot;&gt;std::map&lt;/code&gt; instead guarantees order but costs O(log n) per operation — not always necessary&lt;/li&gt;
&lt;li&gt;For “first non-repeating character” problems, re-traversing the original string (not the map) avoids the ordering issue entirely&lt;/li&gt;
&lt;li&gt;If the problem says “print frequencies in any order,” unordered_map is fine; if it says “print in alphabetical order,” use an array or a sorted container&lt;/li&gt;
&lt;li&gt;The non-determinism is a concern for reproducibility in debugging — a bug that depends on iteration order may not reproduce consistently&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>character-to-index-mapping</title>
    <link href="https://animishraa05.github.io/wiki/strings/character-to-index-mapping" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/character-to-index-mapping.md" />
    <summary>Formal Definition Character-to-index mapping is the transformation of a character to an integer index by subtracting the base character’s ASCII value.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Character-to-index mapping is the transformation of a character to an integer index by subtracting the base character’s ASCII value. For lowercase English letters, &lt;code class=&quot;notranslate&quot;&gt;index = ch - &#039;a&#039;&lt;/code&gt; maps ‘a’→0, ‘b’→1, …, ‘z’→25. This enables using characters as array indices.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;index&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;base&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{index}(c) = \text{ASCII}(c) - \text{ASCII}(\text{base})&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;index&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;base&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Computers store characters as integer codes (ASCII, UTF-8). When characters are contiguous in the encoding — as lowercase letters ‘a’–‘z’ are — subtracting the base character’s code produces a zero-based index. This is the bridge between the character domain and the array-index domain, and it is what makes frequency arrays possible.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Determine the base character (e.g., ‘a’ for lowercase letters, ‘A’ for uppercase)&lt;/li&gt;
&lt;li&gt;Get the ASCII value of the target character: &lt;code class=&quot;notranslate&quot;&gt;int(ch)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Subtract the ASCII value of the base character: &lt;code class=&quot;notranslate&quot;&gt;int(ch) - int(&#039;a&#039;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The result is a zero-based index suitable for array access&lt;/li&gt;
&lt;/ol&gt;
&lt;p dir=&quot;auto&quot;&gt;For &lt;code class=&quot;notranslate&quot;&gt;&#039;a&#039;&lt;/code&gt; through &lt;code class=&quot;notranslate&quot;&gt;&#039;z&#039;&lt;/code&gt;, ASCII values are 97–122, so &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; yields 0–25.&lt;/p&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Given ASCII encoding where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;97&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{ASCII}(&#039;a&#039;) = 97&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;97&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;idx&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mtext&gt;code&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mtext&gt;code&lt;/mtext&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{idx}(c) = \text{code}(c) - \text{code}(&#039;a&#039;)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;idx&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;code&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;code&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;idx&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mn&gt;25&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;for &lt;/mtext&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{idx}(c) \in \{0, 1, 2, \dots, 25\} \quad \text{for } c \in \{&#039;a&#039;, &#039;b&#039;, \dots, &#039;z&#039;\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;idx&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;for &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;∈&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.044em;&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: char_to_index Pages: 1 --&gt;
&lt;svg width=&quot;510pt&quot; height=&quot;98pt&quot; viewBox=&quot;0.00 0.00 510.00 98.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 94)&quot;&gt;
&lt;title&gt;char_to_index&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-94 506.28,-94 506.28,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CHAR --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHAR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;98.38,-90 0,-90 0,-54 98.38,-54 98.38,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;49.19&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Character: &#039;n&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASCII --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ASCII&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;257.78,-90 134.38,-90 134.38,-54 257.78,-54 257.78,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.08&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;ASCII Value: 110&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHAR&amp;#45;&amp;gt;ASCII --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHAR-&gt;ASCII&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M98.84,-72C106.49,-72 114.55,-72 122.6,-72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;122.44,-75.5 132.44,-72 122.44,-68.5 122.44,-75.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SUB --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SUB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;392.68,-63 293.78,-63 293.78,-27 392.68,-27 392.68,-63&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;343.23&quot; y=&quot;-40.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;110 - 97 = 13&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASCII&amp;#45;&amp;gt;SUB --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ASCII-&gt;SUB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M258.22,-60.63C266.22,-59.14 274.41,-57.61 282.4,-56.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;282.82,-59.61 292.01,-54.34 281.54,-52.73 282.82,-59.61&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BASE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BASE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;240.22,-36 151.94,-36 151.94,0 240.22,0 240.22,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.08&quot; y=&quot;-13.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Base &#039;a&#039;: 97&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BASE&amp;#45;&amp;gt;SUB --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BASE-&gt;SUB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M240.63,-26.1C253.74,-28.54 268.37,-31.26 282.34,-33.86&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;281.41,-37.25 291.89,-35.64 282.69,-30.37 281.41,-37.25&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- INDEX --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INDEX&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;502.28,-63 428.68,-63 428.68,-27 502.28,-27 502.28,-63&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;465.48&quot; y=&quot;-40.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Index: 13&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SUB&amp;#45;&amp;gt;INDEX --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SUB-&gt;INDEX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M393.14,-45C401.09,-45 409.31,-45 417.22,-45&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;417.01,-48.5 427.01,-45 417.01,-41.5 417.01,-48.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_char_to_index Pages: 1 --&gt;
&lt;svg width=&quot;318pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 318.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_char_to_index&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 314.41,-205.07 314.41,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;158.56&quot; cy=&quot;-100.51&quot; rx=&quot;98.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.56&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Char-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;229.96&quot; cy=&quot;-59.01&quot; rx=&quot;57.94&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;229.96&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Encoding&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M188.84,-82.91C193.25,-80.35 197.77,-77.72 202.13,-75.19&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;176.98&quot; y=&quot;-70.95&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;158.4&quot; cy=&quot;-18&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.4&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M158.52,-82.2C158.5,-68.53 158.46,-49.92 158.43,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;158.48&quot; y=&quot;-51.13&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;87.82&quot; cy=&quot;-142.96&quot; rx=&quot;87.82&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;87.82&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Index-to-Char Conversion&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M129.38,-118.02C125.11,-120.58 120.73,-123.21 116.48,-125.77&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;143.19&quot; y=&quot;-113.79&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;230.54&quot; cy=&quot;-141.05&quot; rx=&quot;79.87&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;230.54&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M189.5,-117.94C193.16,-120 196.89,-122.1 200.54,-124.15&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;222.53&quot; y=&quot;-123.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;160&quot; cy=&quot;-183.07&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;160&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M158.88,-118.83C159.12,-132.52 159.44,-151.13 159.68,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.04&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;86.78&quot; cy=&quot;-59.9&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;86.78&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M127.7,-83.05C123.9,-80.9 120.03,-78.71 116.25,-76.57&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;135.73&quot; y=&quot;-82.51&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(1) computation — simple integer subtraction&lt;/li&gt;
&lt;li&gt;Requires characters to be contiguous in the encoding&lt;/li&gt;
&lt;li&gt;Only works for a single case at a time (lowercase or uppercase, not both)&lt;/li&gt;
&lt;li&gt;Assumes ASCII encoding (works in C++ on all major platforms)&lt;/li&gt;
&lt;li&gt;The inverse operation is &lt;code class=&quot;notranslate&quot;&gt;i + &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — relies on ASCII values being contiguous integers&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — the mapping is required to index the frequency array&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../index-to-character-conversion&quot; class=&quot;internal alias&quot; data-slug=&quot;index-to-character-conversion&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index-to-Character Conversion&lt;/a&gt; — the mathematical inverse operation&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — hash maps remove the need for this conversion entirely&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — only works when character range is known and contiguous&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Applying &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; to an uppercase character ‘A’–‘Z’ (ASCII 65–90) gives negative indices — undefined behavior&lt;/li&gt;
&lt;li&gt;Applying it to digits, punctuation, or spaces gives unpredictable indices&lt;/li&gt;
&lt;li&gt;Mixing cases silently produces wrong results — ‘A’ maps to -32 (wraps around for unsigned, negative for signed)&lt;/li&gt;
&lt;li&gt;C++ &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt; may be signed or unsigned depending on platform — &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; with negative &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt; values is implementation-defined&lt;/li&gt;
&lt;li&gt;The mapping assumes ASCII; EBCDIC systems do not have contiguous letters&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>direct-array-access</title>
    <link href="https://animishraa05.github.io/wiki/strings/direct-array-access" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/direct-array-access.md" />
    <summary>Formal Definition Direct array access is memory access via base-pointer-plus-offset addressing with no indirection, hashing, or collision resolution.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Direct array access is memory access via base-pointer-plus-offset addressing with no indirection, hashing, or collision resolution. Given a contiguous array and a valid index, the hardware computes the address in a single instruction: &lt;code class=&quot;notranslate&quot;&gt;address = base + index * element_size&lt;/code&gt;. This is the fastest possible random-access lookup.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When you write &lt;code class=&quot;notranslate&quot;&gt;freq[3]&lt;/code&gt;, the CPU computes &lt;code class=&quot;notranslate&quot;&gt;address_of_freq + 3 * sizeof(int)&lt;/code&gt; and fetches the value. No hash function computation, no bucket traversal, no collision chains to follow. For character frequency problems with a small known domain, this makes arrays strictly faster than hash maps despite both being theoretically O(1).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;The array is allocated as a contiguous block of memory&lt;/li&gt;
&lt;li&gt;The compiler knows the base address and element size&lt;/li&gt;
&lt;li&gt;At runtime, &lt;code class=&quot;notranslate&quot;&gt;freq[i]&lt;/code&gt; compiles to a single &lt;code class=&quot;notranslate&quot;&gt;MOV&lt;/code&gt; instruction with scaled index addressing&lt;/li&gt;
&lt;li&gt;The memory access is predictable — adjacent elements are in adjacent memory locations (spatial locality)&lt;/li&gt;
&lt;li&gt;No branching, no function calls, no hash computation&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: direct_access Pages: 1 --&gt;
&lt;svg width=&quot;653pt&quot; height=&quot;51pt&quot; viewBox=&quot;0.00 0.00 653.00 51.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 46.6)&quot;&gt;
&lt;title&gt;direct_access&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-46.6 649.04,-46.6 649.04,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- MEM --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MEM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;591.04,-3.3 591.04,-39.3 645.04,-39.3 645.04,-3.3 591.04,-3.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.04&quot; y=&quot;-17.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;MEM&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CPU --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CPU&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;313.43,-0.5 313.43,-42.1 458.21,-42.1 458.21,-0.5 313.43,-0.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;385.82&quot; y=&quot;-25.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;CPU Instruction&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;385.82&quot; y=&quot;-8.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;MOV eax, [ebx + i*4]&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CPU&amp;#45;&amp;gt;MEM --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CPU-&gt;MEM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M458.4,-21.3C498.37,-21.3 546.55,-21.3 579.25,-21.3&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;579.04,-24.8 589.04,-21.3 579.04,-17.8 579.04,-24.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;524.62&quot; y=&quot;-25.5&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;single instruction&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INDEX --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INDEX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;0,-3.3 0,-39.3 81,-39.3 81,-3.3 0,-3.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;40.5&quot; y=&quot;-17.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Index i=13&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADDR --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ADDR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;118,-3.3 118,-39.3 276.43,-39.3 276.43,-3.3 118,-3.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.21&quot; y=&quot;-17.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Address = base + 13*4&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INDEX&amp;#45;&amp;gt;ADDR --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INDEX-&gt;ADDR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M81.34,-21.3C89.12,-21.3 97.57,-21.3 106.24,-21.3&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;106.21,-24.8 116.21,-21.3 106.21,-17.8 106.21,-24.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ADDR&amp;#45;&amp;gt;CPU --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ADDR-&gt;CPU&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M276.81,-21.3C285.1,-21.3 293.54,-21.3 301.87,-21.3&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;301.63,-24.8 311.63,-21.3 301.63,-17.8 301.63,-24.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_direct_access Pages: 1 --&gt;
&lt;svg width=&quot;327pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 327.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_direct_access&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 323.03,-205.07 323.03,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;161.88&quot; cy=&quot;-100.51&quot; rx=&quot;86.16&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;161.88&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;233.27&quot; cy=&quot;-59.01&quot; rx=&quot;65.48&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;233.27&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Memory Hierarchy&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M191.74,-83.15C196.02,-80.66 200.42,-78.11 204.67,-75.64&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.7&quot; y=&quot;-82.09&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;161.71&quot; cy=&quot;-18&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;161.71&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M161.84,-82.2C161.81,-68.53 161.78,-49.92 161.75,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;141.53&quot; y=&quot;-61.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;91.13&quot; cy=&quot;-142.96&quot; rx=&quot;83.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;91.13&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Memory Efficiency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M133.1,-117.78C128.66,-120.44 124.08,-123.19 119.65,-125.85&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;106.11&quot; y=&quot;-124.51&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;233.86&quot; cy=&quot;-141.05&quot; rx=&quot;85.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;233.86&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M192.4,-117.7C196.08,-119.78 199.84,-121.89 203.51,-123.96&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;225.47&quot; y=&quot;-112.73&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;163.31&quot; cy=&quot;-183.07&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;163.31&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M162.2,-118.83C162.43,-132.52 162.76,-151.13 163,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;176.36&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;90.09&quot; cy=&quot;-59.9&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;90.09&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M131.43,-83.29C127.92,-81.3 124.33,-79.27 120.81,-77.28&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;112.36&quot; y=&quot;-82.98&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;True hardware-level O(1) — single CPU instruction&lt;/li&gt;
&lt;li&gt;No hashing, no collisions, no amortization, no worst-case degradation&lt;/li&gt;
&lt;li&gt;Perfect spatial locality — sequential access is cache-friendly&lt;/li&gt;
&lt;li&gt;Indices must be valid (0 to size-1) — no bounds checking by default in C++&lt;/li&gt;
&lt;li&gt;Works only for contiguous, densely populated index ranges&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — direct access requires valid indices via conversion&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — direct access is the fundamental advantage of arrays&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Array&lt;/a&gt; — minimal overhead per slot enables cache efficiency&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — hash maps trade direct access for flexibility&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../known-range-assumption&quot; class=&quot;internal alias&quot; data-slug=&quot;known-range-assumption&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Known Range Assumption&lt;/a&gt; — direct access requires known, bounded ranges&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Out-of-bounds access leads to undefined behavior (silent memory corruption)&lt;/li&gt;
&lt;li&gt;C++ does not bounds-check array accesses — use &lt;code class=&quot;notranslate&quot;&gt;std::array&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;at()&lt;/code&gt; for safety&lt;/li&gt;
&lt;li&gt;For negative indices (from incorrect &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; on uppercase), the behavior is undefined&lt;/li&gt;
&lt;li&gt;Cache misses can still occur for very large arrays (but for freq[26], the entire array fits in a single cache line)&lt;/li&gt;
&lt;li&gt;Direct access assumes contiguous allocation — vectors also provide this, but with heap allocation overhead&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>frequency-array</title>
    <link href="https://animishraa05.github.io/wiki/strings/frequency-array" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/frequency-array.md" />
    <summary>Formal Definition A frequency array is a fixed-size integer array where each index represents a distinct element from a known, finite domain, and the value at that index stores the count of occurrences of that element in a given dataset.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;A frequency array is a fixed-size integer array where each index represents a distinct element from a known, finite domain, and the value at that index stores the count of occurrences of that element in a given dataset. For lowercase English letters, &lt;code class=&quot;notranslate&quot;&gt;int freq[26]&lt;/code&gt; uses indices 0–25 to represent ‘a’–‘z’.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;freq&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mtext&gt;count of character &lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mtext&gt;’a’&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt; in the input string&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{freq}[i] = \text{count of character } (i + \text{&#039;a&#039;}) \text{ in the input string}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;freq&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;count of character &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;’a’&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; in the input string&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;A frequency array is the simplest possible hash-like structure: instead of hashing keys, you use the key itself (after a trivial transformation) as the array index. When the domain is small and known (like 26 lowercase letters), this gives you O(1) access with zero hashing overhead, zero collision handling, and minimal memory. It is the go-to data structure for character frequency problems in competitive programming and technical interviews.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Declare an array of size equal to the domain size (e.g., &lt;code class=&quot;notranslate&quot;&gt;int freq[26] = {0}&lt;/code&gt; for lowercase letters)&lt;/li&gt;
&lt;li&gt;Iterate through the input string character by character&lt;/li&gt;
&lt;li&gt;Convert each character to its corresponding index using &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Increment &lt;code class=&quot;notranslate&quot;&gt;freq[index]&lt;/code&gt; for each occurrence&lt;/li&gt;
&lt;li&gt;To query, iterate indices 0 through size-1 and check non-zero values&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;For a string &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;S&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; of length &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;n&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; over alphabet &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\Sigma&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;Σ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;|\Sigma| = k&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣Σ∣&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0315em;&quot;&gt;k&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;freq&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msubsup&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/msubsup&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;σ&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{freq}[j] = \sum_{i=1}^{n} [S_i = \sigma_j]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;freq&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.104em;vertical-align:-0.2997em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mop&quot;&gt;&lt;span class=&quot;mop op-symbol small-op&quot; style=&quot;position:relative;top:0em;&quot;&gt;∑&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8043em;&quot;&gt;&lt;span style=&quot;top:-2.4003em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mrel mtight&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.2029em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2997em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0361em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;where &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;[&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;[P]&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the Iverson bracket (1 if &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;P&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; true, 0 otherwise) and &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;σ&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\sigma_j&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7167em;vertical-align:-0.2861em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3117em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.2861em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;j&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.854em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0572em;&quot;&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;-th character of the alphabet.&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: frequency_array Pages: 1 --&gt;
&lt;svg width=&quot;765pt&quot; height=&quot;145pt&quot; viewBox=&quot;0.00 0.00 765.00 145.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 140.8)&quot;&gt;
&lt;title&gt;frequency_array&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-140.8 761.24,-140.8 761.24,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- S --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;S&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;111.11,-77 4.13,-77 4.13,-41 111.11,-41 111.11,-77&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.62&quot; y=&quot;-54.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Input: &#039;banana&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LOOP --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LOOP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;307.55,-77 152.24,-77 152.24,-41 307.55,-41 307.55,-77&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;229.9&quot; y=&quot;-54.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Loop: for each char ch&lt;/text&gt;
&lt;/g&gt;
&lt;!-- S&amp;#45;&amp;gt;LOOP --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;S-&gt;LOOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M111.57,-59C120.86,-59 130.75,-59 140.7,-59&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;140.41,-62.5 150.41,-59 140.41,-55.5 140.41,-62.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- FREQ --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FREQ&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;115.24,-136.8 0,-136.8 0,-95.2 115.24,-95.2 115.24,-136.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.62&quot; y=&quot;-120.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;int freq[26] = {0}&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.62&quot; y=&quot;-103.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;sized for a-z&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;572.25,-131 466.47,-131 466.47,-95 572.25,-95 572.25,-131&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;519.36&quot; y=&quot;-108.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;index = ch - &#039;a&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LOOP&amp;#45;&amp;gt;MAP --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LOOP-&gt;MAP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M307.8,-76.39C313.8,-77.65 319.77,-78.86 325.55,-80 368.59,-88.45 417.27,-96.77 454.95,-102.95&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;454.35,-106.39 464.78,-104.55 455.47,-99.49 454.35,-106.39&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.88&quot; y=&quot;-96.89&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;per character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESULT --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESULT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;622.51,-77 416.21,-77 416.21,-41 622.51,-41 622.51,-77&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;519.36&quot; y=&quot;-54.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[0]=3, freq[1]=1, freq[13]=2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LOOP&amp;#45;&amp;gt;RESULT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LOOP-&gt;RESULT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M307.93,-59C337.61,-59 372.17,-59 404.59,-59&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;404.45,-62.5 414.45,-59 404.45,-55.5 404.45,-62.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.88&quot; y=&quot;-63.2&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;after loop&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INC --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;757.24,-36 659.51,-36 659.51,0 757.24,0 757.24,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;708.37&quot; y=&quot;-13.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[index]++&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;INC --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;INC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M572.55,-103.64C589.06,-99.53 607.03,-93.8 622.51,-86 643.99,-75.17 665.11,-58.28 680.91,-44.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;683.03,-46.84 687.99,-37.49 678.27,-41.71 683.03,-46.84&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- INC&amp;#45;&amp;gt;LOOP --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INC-&gt;LOOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M659.36,-16.14C647.33,-15.75 634.45,-15.4 622.51,-15.2 530.84,-13.69 507.28,-4.58 416.21,-15.2 378.58,-19.59 337.51,-28.82 303.61,-37.69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;303.1,-34.2 294.34,-40.16 304.9,-40.97 303.1,-34.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;519.36&quot; y=&quot;-19.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;next character&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_frequency_array Pages: 1 --&gt;
&lt;svg width=&quot;359pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 359.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 202.54)&quot;&gt;
&lt;title&gt;semantic_frequency_array&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-202.54 354.92,-202.54 354.92,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;174.73&quot; cy=&quot;-99.11&quot; rx=&quot;74.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;174.73&quot; y=&quot;-95.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;256.29&quot; cy=&quot;-120.62&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;256.29&quot; y=&quot;-117.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M225.46,-112.49C225.59,-112.53 225.72,-112.56 225.85,-112.59&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;207.15&quot; y=&quot;-115.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;133.41&quot; cy=&quot;-25.44&quot; rx=&quot;71.92&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;133.41&quot; y=&quot;-22.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Array Data Structure&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M164.52,-80.9C158.16,-69.57 150.01,-55.04 143.65,-43.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;135.58&quot; y=&quot;-54.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;101.67&quot; cy=&quot;-141.11&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.67&quot; y=&quot;-137.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M145.44,-115.95C140.67,-118.69 135.74,-121.53 130.97,-124.27&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;117.94&quot; y=&quot;-112.01&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;217.32&quot; cy=&quot;-171.9&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;217.32&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M185.26,-117.11C191.76,-128.22 200.08,-142.44 206.62,-153.61&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;216.2&quot; y=&quot;-138.06&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT3 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT3&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;153.19&quot; cy=&quot;-180.54&quot; rx=&quot;68.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;153.19&quot; y=&quot;-177.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.95,-117.18C166.41,-130.58 161.59,-148.78 158.03,-162.24&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;184.25&quot; y=&quot;-142.41&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;93.49&quot; cy=&quot;-76.64&quot; rx=&quot;93.49&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;93.49&quot; y=&quot;-73.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map (hash map)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M125.13,-85.39C125,-85.36 124.87,-85.32 124.74,-85.28&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;152.44&quot; y=&quot;-77.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;247.96&quot; cy=&quot;-56.82&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;247.96&quot; y=&quot;-53.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.09,-82.16C209.03,-79.31 214.14,-76.35 219.06,-73.51&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;225.34&quot; y=&quot;-80.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;197.03&quot; cy=&quot;-18&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.03&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Known Range Assumption&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.79,-80.71C183.44,-67.43 188.35,-49.59 191.99,-36.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;172.13&quot; y=&quot;-50.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(1) time for both insertion and lookup — true constant time, no amortization&lt;/li&gt;
&lt;li&gt;Memory proportional to domain size (&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;Σ&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;O(|\Sigma|)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣Σ∣&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;), not input size (&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;O&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;O(n)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Zero hashing overhead — no hash function computation, no collision resolution&lt;/li&gt;
&lt;li&gt;Only works when the domain is known, finite, and contiguous (or near-contiguous)&lt;/li&gt;
&lt;li&gt;Access pattern is predictable — sequential memory access when iterating&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — the &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; conversion is required to map characters to array indices&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing&lt;/a&gt; — frequency arrays are the storage mechanism in Phase 1&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — traversing the array finds the max frequency&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — comparing two frequency arrays checks anagrams&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency&lt;/a&gt; — maps offer flexibility but with hashing overhead&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — no hashing means truly direct memory access&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Forgetting to zero-initialize the array (&lt;code class=&quot;notranslate&quot;&gt;int freq[26] = {0}&lt;/code&gt;) leads to garbage values&lt;/li&gt;
&lt;li&gt;Using &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; on uppercase letters or non-alphabetic characters produces negative indices or out-of-bounds access&lt;/li&gt;
&lt;li&gt;Array size must match the domain — &lt;code class=&quot;notranslate&quot;&gt;freq[26]&lt;/code&gt; fails for extended ASCII or Unicode&lt;/li&gt;
&lt;li&gt;Iterating all 26 slots when only 3 characters appeared wastes time (minor but relevant for sparse data)&lt;/li&gt;
&lt;li&gt;The array stores frequencies, not positions — cannot directly answer “where does character X first appear?”&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hash-collision-overhead</title>
    <link href="https://animishraa05.github.io/wiki/strings/hash-collision-overhead" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/hash-collision-overhead.md" />
    <summary>Formal Definition Hash collision overhead is the performance penalty incurred when two distinct keys hash to the same bucket in a hash table, requiring additional comparisons to resolve the collision.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-08-08T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Aug 08, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hash collision overhead is the performance penalty incurred when two distinct keys hash to the same bucket in a hash table, requiring additional comparisons to resolve the collision. In &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt;, collisions are resolved via chaining (linked lists), making lookup O(k) where k is the bucket chain length.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When you claim &lt;code class=&quot;notranslate&quot;&gt;unordered_map&lt;/code&gt; offers O(1) access, the fine print is “average O(1) assuming a good hash function.” Collisions occur when different characters produce the same hash bucket. The map must then walk a linked list of entries to find the right one. In the worst case (all keys colliding), lookup degrades to O(n). A frequency array never has this problem because array indexing is collision-free by design.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;When inserting &lt;code class=&quot;notranslate&quot;&gt;freq[ch]&lt;/code&gt;, the map computes &lt;code class=&quot;notranslate&quot;&gt;hash(ch) % bucket_count&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If the bucket is empty, the entry is placed directly&lt;/li&gt;
&lt;li&gt;If the bucket already has entries (collision), the new entry is appended to the chain&lt;/li&gt;
&lt;li&gt;On lookup, the map hashes the key, goes to the bucket, and walks the chain comparing keys&lt;/li&gt;
&lt;li&gt;With a good hash function and adequate bucket count, chain length averages O(1)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: collision Pages: 1 --&gt;
&lt;svg width=&quot;767pt&quot; height=&quot;98pt&quot; viewBox=&quot;0.00 0.00 767.00 98.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 94)&quot;&gt;
&lt;title&gt;collision&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-94 762.95,-94 762.95,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- HASH1 --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HASH1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;156.35,-90 33.45,-90 33.45,-54 156.35,-54 156.35,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;94.9&quot; y=&quot;-67.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;hash(&#039;a&#039;) % N = 3&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BUCKET --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BUCKET&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;405.53,-65.8 314.43,-65.8 314.43,-24.2 405.53,-24.2 405.53,-65.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;359.98&quot; y=&quot;-49.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Bucket 3&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;359.98&quot; y=&quot;-32.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;[a:3] -&gt; [n:2]&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HASH1&amp;#45;&amp;gt;BUCKET --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HASH1-&gt;BUCKET&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M156.59,-65.77C200.65,-61.25 259.83,-55.18 302.81,-50.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;303.11,-54.25 312.7,-49.75 302.39,-47.29 303.11,-54.25&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.11&quot; y=&quot;-64.32&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;first entry&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HASH2 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HASH2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;189.8,-36 0,-36 0,0 189.8,0 189.8,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;94.9&quot; y=&quot;-13.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;hash(&#039;n&#039;) % N = 3 (collision!)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HASH2&amp;#45;&amp;gt;BUCKET --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HASH2-&gt;BUCKET&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M190.06,-21.25C223.73,-23.19 261.89,-26.28 296.43,-31.2 298.58,-31.51 300.76,-31.84 302.96,-32.21&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;302.08,-35.61 312.54,-33.96 303.33,-28.72 302.08,-35.61&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.11&quot; y=&quot;-35.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;append to chain&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COMPARE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COMPARE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;758.95,-65.8 593.54,-65.8 593.54,-24.2 758.95,-24.2 758.95,-65.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;676.25&quot; y=&quot;-49.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Compare key &#039;n&#039;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;676.25&quot; y=&quot;-32.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;walk chain to find match&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BUCKET&amp;#45;&amp;gt;COMPARE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BUCKET-&gt;COMPARE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M406.01,-45C451.67,-45 523.7,-45 581.76,-45&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;581.67,-48.5 591.67,-45 581.67,-41.5 581.67,-48.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.54&quot; y=&quot;-49.2&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;lookup requires chain walk&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_collision_overhead Pages: 1 --&gt;
&lt;svg width=&quot;344pt&quot; height=&quot;194pt&quot; viewBox=&quot;0.00 0.00 344.00 194.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 189.56)&quot;&gt;
&lt;title&gt;semantic_collision_overhead&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-189.56 339.78,-189.56 339.78,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;147.98&quot; cy=&quot;-86.38&quot; rx=&quot;105.8&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;147.98&quot; y=&quot;-82.48&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;199.84&quot; cy=&quot;-23.83&quot; rx=&quot;53.78&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;199.84&quot; y=&quot;-20.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Function&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M162.98,-68.29C170.04,-59.77 178.43,-49.66 185.41,-41.24&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;155.69&quot; y=&quot;-57.46&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;104.23&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;104.23&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M136.26,-68.05C129.88,-58.09 122.02,-45.8 115.68,-35.9&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.71&quot; y=&quot;-54.68&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;69.64&quot; cy=&quot;-107.72&quot; rx=&quot;69.64&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;69.64&quot; y=&quot;-104.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Direct Array Access&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M91.05,-101.89C90.95,-101.92 90.86,-101.94 90.76,-101.97&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;63.4&quot; y=&quot;-104.63&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;223.77&quot; cy=&quot;-115.84&quot; rx=&quot;112.01&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;223.77&quot; y=&quot;-112.54&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Non-Determinism&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M191.19,-103.17C191.32,-103.22 191.46,-103.28 191.59,-103.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;177.63&quot; y=&quot;-105.95&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;144.15&quot; cy=&quot;-167.56&quot; rx=&quot;101.04&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;144.15&quot; y=&quot;-164.26&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Interview Decision Framework&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M147.11,-104.8C146.49,-118.09 145.64,-135.95 145.02,-149.22&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;132.31&quot; y=&quot;-129.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Average-case O(1) degrades to worst-case O(n) with poor hash distribution&lt;/li&gt;
&lt;li&gt;Frequency arrays have zero collision overhead — index can only map to one location&lt;/li&gt;
&lt;li&gt;C++ &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&lt;/code&gt; uses chaining, so collisions add pointer indirection&lt;/li&gt;
&lt;li&gt;Rehashing (when load factor exceeds threshold) is O(n) — a costly amortized operation&lt;/li&gt;
&lt;li&gt;For small character sets (26 letters), maps are overkill and collisions are wasted work&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../direct-array-access&quot; class=&quot;internal alias&quot; data-slug=&quot;direct-array-access&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Direct Array Access&lt;/a&gt; — arrays bypass the collision problem entirely&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency&lt;/a&gt; — collision handling is part of the map’s implementation cost&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — collision overhead is the cost of hash map flexibility&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../memory-efficiency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;memory-efficiency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Memory Efficiency of Array&lt;/a&gt; — arrays have predictable, linear memory with no overhead&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../unordered-map-non-determinism&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-non-determinism&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map Non-Determinism&lt;/a&gt; — collision resolution affects iteration order&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;For character keys, C++‘s default hash for &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt; is usually good — collisions are rare but possible&lt;/li&gt;
&lt;li&gt;String keys (for word frequency) have a higher collision probability than single chars&lt;/li&gt;
&lt;li&gt;A maliciously crafted input can trigger many collisions, causing O(n²) behavior — hash DoS attack&lt;/li&gt;
&lt;li&gt;The “average O(1)” claim assumes the hash function is well-distributed — never guaranteed for arbitrary keys&lt;/li&gt;
&lt;li&gt;Rehashing invalidates all iterators — a subtle bug when interleaving Phase 1 traversal with Phase 2&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hashing-retrieval-phase</title>
    <link href="https://animishraa05.github.io/wiki/strings/hashing-retrieval-phase" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/hashing-retrieval-phase.md" />
    <summary>Formal Definition The hashing retrieval phase (Phase 2) is the process of querying the hash structure built in Phase 1 to produce the answer to a specific problem.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The hashing retrieval phase (Phase 2) is the process of querying the hash structure built in Phase 1 to produce the answer to a specific problem. The retrieval strategy varies by problem — traversing the structure, re-traversing the input, or comparing multiple structures.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Phase 2 is where the actual problem-solving happens. While Phase 1 is nearly identical across all frequency-counting problems, Phase 2 diverges dramatically. For “most frequent character” you traverse the structure tracking a max variable. For “first non-repeating” you re-traverse the original string. For “anagram” you compare two structures. Mastering Phase 2 is what separates strong candidates from beginners.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Determine the query pattern based on the problem&lt;/li&gt;
&lt;li&gt;If finding max/min: traverse the hash structure, maintain tracking variables&lt;/li&gt;
&lt;li&gt;If order-sensitive (first non-repeating): re-traverse the original string, check hash structure&lt;/li&gt;
&lt;li&gt;If comparing two datasets: build two Phase 1 structures, then compare element by element&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: retrieval_phase Pages: 1 --&gt;
&lt;svg width=&quot;541pt&quot; height=&quot;234pt&quot; viewBox=&quot;0.00 0.00 541.00 234.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 229.8)&quot;&gt;
&lt;title&gt;retrieval_phase&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-229.8 536.95,-229.8 536.95,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- STRUCT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STRUCT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;334.33,-225.8 191.5,-225.8 191.5,-184.2 334.33,-184.2 334.33,-225.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-209.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Frequency Structure&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-192.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:3, b:1, n:2}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROBLEM --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROBLEM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;262.91,-147.2 148.63,-129.2 262.91,-111.2 377.19,-129.2 262.91,-147.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-125&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Which problem?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STRUCT&amp;#45;&amp;gt;PROBLEM --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STRUCT-&gt;PROBLEM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M262.91,-183.83C262.91,-176.06 262.91,-167.03 262.91,-158.62&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;266.41,-158.85 262.91,-148.85 259.41,-158.85 266.41,-158.85&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MAX --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;163.83,-58.4 0,-58.4 0,0 163.83,0 163.83,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;81.91&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Most Frequent:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;81.91&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Traverse freq struct&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;81.91&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Track max count &amp;#x26; char&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROBLEM&amp;#45;&amp;gt;MAX --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROBLEM-&gt;MAX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M238.13,-114.78C214.08,-101.76 176.62,-81.48 144.41,-64.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;146.39,-61.13 135.93,-59.45 143.06,-67.29 146.39,-61.13&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;219.02&quot; y=&quot;-80.6&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;max freq&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FIRST --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FIRST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;344.45,-58.4 181.38,-58.4 181.38,0 344.45,0 344.45,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;First Non-Repeat:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Re-traverse string&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.91&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;If freq[ch]==1 → answer&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROBLEM&amp;#45;&amp;gt;FIRST --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROBLEM-&gt;FIRST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M262.91,-111.13C262.91,-99.71 262.91,-84.18 262.91,-69.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;266.41,-70.09 262.91,-60.09 259.41,-70.09 266.41,-70.09&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;314.81&quot; y=&quot;-80.6&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;first non-repeating&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANA --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ANA&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;532.95,-58.4 362.88,-58.4 362.88,0 532.95,0 532.95,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;447.91&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Anagram:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;447.91&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Build freq for string 2&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;447.91&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Compare both structures&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROBLEM&amp;#45;&amp;gt;ANA --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROBLEM-&gt;ANA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M307.53,-117.78C327.62,-112.08 351.19,-103.96 370.91,-93.2 384.45,-85.82 397.9,-75.92 409.69,-66.17&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;411.86,-68.91 417.2,-59.76 407.32,-63.59 411.86,-68.91&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;420.14&quot; y=&quot;-80.6&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;anagram&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_retrieval_phase Pages: 1 --&gt;
&lt;svg width=&quot;326pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 326.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_retrieval_phase&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 322.3,-203.13 322.3,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;160.48&quot; cy=&quot;-99.52&quot; rx=&quot;105.33&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;160.48&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;244.09&quot; cy=&quot;-100.14&quot; rx=&quot;74.21&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;244.09&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Store Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M244.03,-100.14C244.05,-100.14 244.06,-100.14 244.07,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;225.54&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;142.56&quot; cy=&quot;-18&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.56&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M156.5,-81.43C153.55,-68.01 149.55,-49.79 146.59,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;170.05&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;85.54&quot; cy=&quot;-136.37&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;85.54&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M125.2,-116.87C123.38,-117.76 121.55,-118.66 119.73,-119.56&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.21&quot; y=&quot;-120.91&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;212.68&quot; cy=&quot;-164.83&quot; rx=&quot;102.56&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;212.68&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;First Non-Repeating Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M175.02,-117.71C182.26,-126.77 190.98,-137.69 198.21,-146.74&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.88&quot; y=&quot;-134.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT3 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT3&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;142.52&quot; cy=&quot;-181.13&quot; rx=&quot;68.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.52&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M156.49,-117.63C153.53,-131.06 149.52,-149.3 146.55,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;161.65&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;85.26&quot; cy=&quot;-63.33&quot; rx=&quot;77.98&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;85.26&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Map Traversal Method&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M124.63,-82.27C122.97,-81.47 121.3,-80.67 119.64,-79.87&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;108.37&quot; y=&quot;-83.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;213.29&quot; cy=&quot;-34.8&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;213.29&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M175.19,-81.49C182.51,-72.51 191.34,-61.69 198.66,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;200.68&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Problem-dependent — Phase 2 looks different for every problem type&lt;/li&gt;
&lt;li&gt;May or may not be O(n) — depends on whether it traverses the structure or re-traverses the input&lt;/li&gt;
&lt;li&gt;For array-based Phase 1: traversal is over domain size (26), input re-traversal is over n&lt;/li&gt;
&lt;li&gt;For map-based Phase 1: traversal is over distinct elements (m ≤ n), input re-traversal is over n&lt;/li&gt;
&lt;li&gt;Some queries can short-circuit early (first non-repeating can stop at first match)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-store-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-store-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Store Phase&lt;/a&gt; — Phase 2 consumes data produced by Phase 1&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — Phase 2 is the second half of the paradigm&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — traverses structure tracking max&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — re-traverses input checking structure&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — compares two structures&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;For first non-repeating character, the naive Phase 2 is O(n²) without the hash structure — the hash makes it O(n)&lt;/li&gt;
&lt;li&gt;Most frequent character with ties: which character do you return? The problem usually expects any or the first; clarify with the interviewer&lt;/li&gt;
&lt;li&gt;For maps, traversal order is non-deterministic — do not rely on order for correctness&lt;/li&gt;
&lt;li&gt;For anagrams, comparing two maps must account for characters present in one but not the other&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hashing-store-phase</title>
    <link href="https://animishraa05.github.io/wiki/strings/hashing-store-phase" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/hashing-store-phase.md" />
    <summary>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.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;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.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;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.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Initialize the structure: &lt;code class=&quot;notranslate&quot;&gt;int freq[26] = {0}&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char,int&gt; freq&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Iterate through each character in the input string&lt;/li&gt;
&lt;li&gt;For arrays: compute &lt;code class=&quot;notranslate&quot;&gt;index = ch - &#039;a&#039;&lt;/code&gt;, then &lt;code class=&quot;notranslate&quot;&gt;freq[index]++&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For maps: simply &lt;code class=&quot;notranslate&quot;&gt;freq[ch]++&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;After iteration, the structure contains all frequency information&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: store_phase Pages: 1 --&gt;
&lt;svg width=&quot;824pt&quot; height=&quot;88pt&quot; viewBox=&quot;0.00 0.00 824.00 88.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 83.8)&quot;&gt;
&lt;title&gt;store_phase&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-83.8 820.44,-83.8 820.44,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- START --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;START&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;127.27,-41.6 0,-41.6 0,0 127.27,0 127.27,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;63.63&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Initialize Structure&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;63.63&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;int freq[26] = {0}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHAR --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHAR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;266.63,-41.6 164.27,-41.6 164.27,0 266.63,0 266.63,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;215.45&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Get Next char&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;215.45&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;from string&lt;/text&gt;
&lt;/g&gt;
&lt;!-- START&amp;#45;&amp;gt;CHAR --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;START-&gt;CHAR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M127.74,-20.8C136,-20.8 144.46,-20.8 152.7,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;152.64,-24.3 162.64,-20.8 152.64,-17.3 152.64,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- UPDATE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;UPDATE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;408.25,-79.8 303.63,-79.8 303.63,-43.8 408.25,-43.8 408.25,-79.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;355.94&quot; y=&quot;-57.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[ch - &#039;a&#039;]++&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHAR&amp;#45;&amp;gt;UPDATE --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHAR-&gt;UPDATE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M266.84,-35.72C275.22,-38.2 283.99,-40.79 292.62,-43.35&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;291.39,-46.64 301.97,-46.12 293.38,-39.92 291.39,-46.64&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MORE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MORE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;536.76,-38.8 445.25,-20.8 536.76,-2.8 628.26,-20.8 536.76,-38.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;536.76&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;More chars?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- UPDATE&amp;#45;&amp;gt;MORE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;UPDATE-&gt;MORE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M408.66,-49.94C431.62,-44.68 458.64,-38.48 481.84,-33.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;482.46,-36.61 491.42,-30.97 480.89,-29.79 482.46,-36.61&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MORE&amp;#45;&amp;gt;CHAR --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MORE-&gt;CHAR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M453.57,-18.68C409.17,-17.82 353.4,-17.2 303.63,-18 295.32,-18.13 286.55,-18.34 277.92,-18.58&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;278.1,-15.07 268.21,-18.87 278.31,-22.07 278.1,-15.07&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;355.94&quot; y=&quot;-22.2&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;yes&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DONE --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DONE&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;816.44,-41.6 678.26,-41.6 678.26,0 816.44,0 816.44,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;747.35&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 1 Complete&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;747.35&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Frequencies Stored&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MORE&amp;#45;&amp;gt;DONE --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MORE-&gt;DONE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M630.77,-20.8C642.67,-20.8 654.76,-20.8 666.42,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;666.41,-24.3 676.41,-20.8 666.41,-17.3 666.41,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;653.26&quot; y=&quot;-25&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;no&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_store_phase Pages: 1 --&gt;
&lt;svg width=&quot;338pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 338.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_store_phase&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 334.36,-205.07 334.36,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;173.59&quot; cy=&quot;-100.51&quot; rx=&quot;91.94&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.59&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hashing Store Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;244.98&quot; cy=&quot;-59.01&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;244.98&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M203.45,-83.15C207.89,-80.58 212.44,-77.93 216.84,-75.37&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;191.64&quot; y=&quot;-81.96&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;173.42&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.42&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M173.55,-82.2C173.53,-68.53 173.49,-49.92 173.46,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.25&quot; y=&quot;-51.13&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;102.84&quot; cy=&quot;-142.96&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.84&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M144.41,-118.02C139.99,-120.67 135.44,-123.4 131.05,-126.04&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;157.99&quot; y=&quot;-113.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;245.57&quot; cy=&quot;-141.05&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245.57&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.53,-117.94C208.04,-119.91 211.61,-121.92 215.11,-123.9&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;230.08&quot; y=&quot;-123.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;175.03&quot; cy=&quot;-183.07&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;175.03&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M173.91,-118.83C174.15,-132.52 174.47,-151.13 174.71,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;188.07&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;101.81&quot; cy=&quot;-59.9&quot; rx=&quot;101.81&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.81&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character Hashing Use Cases&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M143.15,-83.29C139.63,-81.3 136.05,-79.27 132.53,-77.28&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;151.6&quot; y=&quot;-82.98&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Always O(n) time — must visit each element once&lt;/li&gt;
&lt;li&gt;O(k) space where k is the domain size (for arrays) or O(m) where m is distinct elements (for maps)&lt;/li&gt;
&lt;li&gt;Structure choice (array vs map) is locked in during Phase 1&lt;/li&gt;
&lt;li&gt;No conditional logic — just increment operations&lt;/li&gt;
&lt;li&gt;Order of iteration does not matter for frequency counting&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — one implementation choice for Phase 1&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../unordered-map-frequency&quot; class=&quot;internal alias&quot; data-slug=&quot;unordered-map-frequency&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Unordered Map for Frequency&lt;/a&gt; — another implementation choice for Phase 1&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — Phase 1 is the first half of the paradigm&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — Phase 1 feeds data into Phase 2&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — used only in the array variant of Phase 1&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;For empty strings, Phase 1 produces an empty structure — Phase 2 must handle this&lt;/li&gt;
&lt;li&gt;For strings with a single character, the structure has one entry — still correct&lt;/li&gt;
&lt;li&gt;For maps, repeated &lt;code class=&quot;notranslate&quot;&gt;freq[ch]++&lt;/code&gt; calls may trigger rehashing (amortized O(1), but costly)&lt;/li&gt;
&lt;li&gt;Phase 1 cannot answer any question about the data until it completes — it is purely a gathering phase&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>index-to-character-conversion</title>
    <link href="https://animishraa05.github.io/wiki/strings/index-to-character-conversion" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/index-to-character-conversion.md" />
    <summary>1 Formal Definition Index-to-character conversion is the inverse of character-to-index mapping.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;p dir=&quot;auto&quot;&gt;1&lt;/p&gt;
&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Index-to-character conversion is the inverse of character-to-index mapping. Given an integer index i (0–25 for lowercase English), adding the base character’s ASCII value produces the corresponding character: &lt;code class=&quot;notranslate&quot;&gt;ch = i + &#039;a&#039;&lt;/code&gt;.&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;char&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msup&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;mrow&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{char}(i) = \text{ASCII}^{-1}(\text{ASCII}(&#039;a&#039;) + i)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.1373em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8873em;&quot;&gt;&lt;span style=&quot;top:-3.1362em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;After building a frequency array, the stored data is indexed numerically (0–25). To produce human-readable output (printing “a = 3” not “0 = 3”), you must convert each index back to its character. This is the reverse of the &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; mapping and uses &lt;code class=&quot;notranslate&quot;&gt;i + &#039;a&#039;&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;During traversal of the frequency array, you have an index &lt;code class=&quot;notranslate&quot;&gt;i&lt;/code&gt; (0 to 25)&lt;/li&gt;
&lt;li&gt;Compute &lt;code class=&quot;notranslate&quot;&gt;char ch = i + &#039;a&#039;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;code class=&quot;notranslate&quot;&gt;ch&lt;/code&gt; for output or further processing&lt;/li&gt;
&lt;li&gt;For i=0 → ‘a’, i=1 → ‘b’, …, i=25 → ‘z’&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;char&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;97&lt;/mn&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mtext&gt;ASCII&lt;/mtext&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{char}(i) = i + 97 = i + \text{ASCII}(&#039;a&#039;)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7429em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7429em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;ASCII&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;char&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;char&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;char&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mn&gt;25&lt;/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;msup&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;msup&gt;&lt;mi&gt;z&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{char}(0) = &#039;a&#039;, \quad \text{char}(1) = &#039;b&#039;, \quad \dots, \quad \text{char}(25) = &#039;z&#039;&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.0019em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;char&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.044em;&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.7519em;&quot;&gt;&lt;span style=&quot;top:-3.063em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;′&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: index_to_char Pages: 1 --&gt;
&lt;svg width=&quot;790pt&quot; height=&quot;137pt&quot; viewBox=&quot;0.00 0.00 790.00 137.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 133.38)&quot;&gt;
&lt;title&gt;index_to_char&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-133.38 786.49,-133.38 786.49,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- FREQ --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FREQ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;119.48,-106.6 0,-106.6 0,-31.4 119.48,-31.4 119.48,-106.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.74&quot; y=&quot;-90&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.74&quot; y=&quot;-73.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;i=0: 3&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.74&quot; y=&quot;-56.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;i=1: 1&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.74&quot; y=&quot;-39.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;i=13: 2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LOOP --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LOOP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;249.94,-87 156.48,-87 156.48,-51 249.94,-51 249.94,-87&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;203.21&quot; y=&quot;-64.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Loop i=0..25&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FREQ&amp;#45;&amp;gt;LOOP --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;FREQ-&gt;LOOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M119.92,-69C128.15,-69 136.6,-69 144.8,-69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;144.67,-72.5 154.67,-69 144.67,-65.5 144.67,-72.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CHECK --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CHECK&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;367.46,-87 286.94,-69 367.46,-51 447.98,-69 367.46,-87&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;367.46&quot; y=&quot;-64.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[i] &gt; 0?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LOOP&amp;#45;&amp;gt;CHECK --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LOOP-&gt;CHECK&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M250.27,-69C257.59,-69 265.39,-69 273.34,-69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;273.14,-72.5 283.14,-69 273.14,-65.5 273.14,-72.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CONV --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONV&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;610.79,-96 531.85,-96 531.85,-60 610.79,-60 610.79,-96&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;571.32&quot; y=&quot;-73.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;ch = i + &#039;a&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHECK&amp;#45;&amp;gt;CONV --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHECK-&gt;CONV&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M436.52,-72.03C463.91,-73.26 494.93,-74.64 520.21,-75.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;519.72,-79.25 529.87,-76.2 520.03,-72.25 519.72,-79.25&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;481.72&quot; y=&quot;-78.77&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;yes&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SKIP --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SKIP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;627.17,-36 515.47,-36 515.47,0 627.17,0 627.17,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;571.32&quot; y=&quot;-13.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Skip (zero freq)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CHECK&amp;#45;&amp;gt;SKIP --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CHECK-&gt;SKIP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M406.43,-59.41C433.93,-52.46 471.81,-42.89 504.22,-34.7&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;504.68,-38.19 513.52,-32.35 502.96,-31.41 504.68,-38.19&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;481.72&quot; y=&quot;-47.7&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;no&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRINT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRINT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;782.49,-119 664.17,-119 664.17,-83 782.49,-83 782.49,-119&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;723.33&quot; y=&quot;-96.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Print: ch = freq[i]&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONV&amp;#45;&amp;gt;PRINT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CONV-&gt;PRINT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M610.95,-83.92C623.62,-85.87 638.12,-88.09 652.38,-90.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;651.81,-93.73 662.22,-91.78 652.87,-86.81 651.81,-93.73&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PRINT&amp;#45;&amp;gt;LOOP --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PRINT-&gt;LOOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M664,-106.4C579.92,-112.81 420.13,-119.88 286.94,-96 278.37,-94.46 269.46,-92.25 260.8,-89.74&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;262.05,-86.46 251.46,-86.88 260,-93.15 262.05,-86.46&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;481.72&quot; y=&quot;-116.78&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;next i&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SKIP&amp;#45;&amp;gt;LOOP --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SKIP-&gt;LOOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M515.22,-12.05C457.35,-7.49 364.18,-4.97 286.94,-25.2 271,-29.37 254.71,-37.11 240.85,-44.94&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;239.37,-41.75 232.53,-49.83 242.92,-47.78 239.37,-41.75&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;367.46&quot; y=&quot;-29.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;next i&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_index_to_char Pages: 1 --&gt;
&lt;svg width=&quot;330pt&quot; height=&quot;209pt&quot; viewBox=&quot;0.00 0.00 330.00 209.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 205.07)&quot;&gt;
&lt;title&gt;semantic_index_to_char&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-205.07 326.31,-205.07 326.31,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;156.29&quot; cy=&quot;-100.51&quot; rx=&quot;109.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;156.29&quot; y=&quot;-96.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Index-to-Char Conversion&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;227.68&quot; cy=&quot;-59.01&quot; rx=&quot;94.63&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;227.68&quot; y=&quot;-55.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Character-to-Index Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M186.57,-82.91C190.21,-80.79 193.94,-78.62 197.59,-76.5&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.57&quot; y=&quot;-82.41&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;156.12&quot; cy=&quot;-18&quot; rx=&quot;90.45&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;156.12&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array Traversal&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M156.25,-82.2C156.22,-68.53 156.19,-49.92 156.16,-36.26&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;176.47&quot; y=&quot;-61.93&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;85.54&quot; cy=&quot;-142.96&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;85.54&quot; y=&quot;-139.66&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M126.7,-118.27C122.61,-120.72 118.41,-123.24 114.34,-125.68&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;140.78&quot; y=&quot;-113.88&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;228.27&quot; cy=&quot;-141.05&quot; rx=&quot;71.16&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;228.27&quot; y=&quot;-137.75&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Traversal&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M187.65,-118.18C191.29,-120.22 194.99,-122.31 198.6,-124.34&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.63&quot; y=&quot;-123.96&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;157.73&quot; cy=&quot;-183.07&quot; rx=&quot;57.94&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;157.73&quot; y=&quot;-179.77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Encoding&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M156.61,-118.83C156.85,-132.52 157.17,-151.13 157.41,-164.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;143.25&quot; y=&quot;-144.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;84.51&quot; cy=&quot;-59.9&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;84.51&quot; y=&quot;-56.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M125.01,-82.82C121.08,-80.59 117.08,-78.33 113.19,-76.13&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.34&quot; y=&quot;-82.17&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;O(1) computation — simple integer addition&lt;/li&gt;
&lt;li&gt;Must match the base used in the forward mapping (&lt;code class=&quot;notranslate&quot;&gt;&#039;a&#039;&lt;/code&gt; for &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Produces only lowercase letters when used with 0–25 indices&lt;/li&gt;
&lt;li&gt;No bounds checking — caller must ensure index is in valid range&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../character-to-index-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;character-to-index-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character-to-Index Mapping&lt;/a&gt; — index-to-character is the mathematical inverse of character-to-index&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — after finding the max index, convert back to character&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — used during the traversal phase to produce output&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../map-traversal-method&quot; class=&quot;internal alias&quot; data-slug=&quot;map-traversal-method&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Traversal Method&lt;/a&gt; — maps store key-value pairs directly, no conversion needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Using &lt;code class=&quot;notranslate&quot;&gt;&#039;A&#039;&lt;/code&gt; as base when the mapping used &lt;code class=&quot;notranslate&quot;&gt;&#039;a&#039;&lt;/code&gt; produces wrong letters&lt;/li&gt;
&lt;li&gt;Indices outside 0–25 produce non-alphabetic characters (e.g., i=26 → ’{’)&lt;/li&gt;
&lt;li&gt;Forgetting this step and printing raw indices is a common beginner mistake&lt;/li&gt;
&lt;li&gt;When using uppercase mapping (&lt;code class=&quot;notranslate&quot;&gt;ch - &#039;A&#039;&lt;/code&gt;), the reverse must use &lt;code class=&quot;notranslate&quot;&gt;i + &#039;A&#039;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>two-phase-hashing</title>
    <link href="https://animishraa05.github.io/wiki/strings/two-phase-hashing" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/two-phase-hashing.md" />
    <summary>Formal Definition Two-phase hashing is the conceptual separation of hash-based problem solving into two distinct phases: Phase 1 (information storage) builds the frequency or mapping structure by processing the input, and Phase 2 (information retrieval) queries that structure to answer the specific ...</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Two-phase hashing is the conceptual separation of hash-based problem solving into two distinct phases: Phase 1 (information storage) builds the frequency or mapping structure by processing the input, and Phase 2 (information retrieval) queries that structure to answer the specific problem. Both phases use the same underlying hash structure but with different access patterns.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Beginners often stop after building the frequency structure, unsure what to do next. The key insight is that building the hash is only half the work — the real problem-solving happens in Phase 2, where you traverse or query the structure differently depending on the question. Different problems (most frequent, first non-repeating, anagram detection) all share Phase 1 but diverge in Phase 2.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Phase 1 (Store):&lt;/strong&gt; Choose a structure (array or hash map), iterate the input, populate frequencies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phase 2 (Use):&lt;/strong&gt; Query the structure — this could mean finding the max, re-traversing the input for order, or comparing two frequency maps&lt;/li&gt;
&lt;li&gt;The distinction is mental but powerful: it separates mechanical work from analytical work&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;mathematical-formulation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mathematical Formulation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mathematical-formulation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;Phase 1: &lt;/mtext&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo&gt;←&lt;/mo&gt;&lt;mtext&gt;build&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;where &lt;/mtext&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mtext&gt; is the hash structure&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Phase 1: } H \leftarrow \text{build}(S) \quad \text{where } H \text{ is the hash structure}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Phase 1: &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;←&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;build&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;where &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt; is the hash structure&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mtext&gt;Phase 2: answer&lt;/mtext&gt;&lt;mo&gt;←&lt;/mo&gt;&lt;mtext&gt;query&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;or&lt;/mtext&gt;&lt;mspace width=&quot;1em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;answer&lt;/mtext&gt;&lt;mo&gt;←&lt;/mo&gt;&lt;mtext&gt;query&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;H&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\text{Phase 2: } \text{answer} \leftarrow \text{query}(H, S) \quad \text{or} \quad \text{answer} \leftarrow \text{query}(H)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;Phase 2: &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;answer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;←&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;query&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0576em;&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:1em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;answer&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;←&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord text&quot;&gt;&lt;span class=&quot;mord&quot;&gt;query&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0813em;&quot;&gt;H&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: two_phase_hashing Pages: 1 --&gt;
&lt;svg width=&quot;518pt&quot; height=&quot;377pt&quot; viewBox=&quot;0.00 0.00 518.00 377.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 372.8)&quot;&gt;
&lt;title&gt;two_phase_hashing&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-372.8 514.24,-372.8 514.24,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- INPUT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INPUT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;306.42,-368.8 218.82,-368.8 218.82,-327.2 306.42,-327.2 306.42,-368.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-352.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Input String&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-335.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;&#039;banana&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P1&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;351.55,-291.2 173.69,-291.2 173.69,-249.6 351.55,-249.6 351.55,-291.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-274.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 1: Store&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-257.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Build Frequency Structure&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INPUT&amp;#45;&amp;gt;P1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INPUT-&gt;P1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M262.62,-326.74C262.62,-319.39 262.62,-310.91 262.62,-302.83&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;266.12,-302.97 262.62,-292.97 259.12,-302.97 266.12,-302.97&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- STRUCT --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STRUCT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;319.25,-213.6 205.99,-213.6 205.99,-172 319.25,-172 319.25,-213.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-197&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Frequency Map&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-180.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:3, b:1, n:2}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P1&amp;#45;&amp;gt;STRUCT --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P1-&gt;STRUCT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M262.62,-249.14C262.62,-241.79 262.62,-233.31 262.62,-225.23&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;266.12,-225.37 262.62,-215.37 259.12,-225.37 266.12,-225.37&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- P2 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P2&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;325.08,-136 200.16,-136 200.16,-94.4 325.08,-94.4 325.08,-136&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-119.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Phase 2: Use&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;262.62&quot; y=&quot;-102.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Query for Answer&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STRUCT&amp;#45;&amp;gt;P2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STRUCT-&gt;P2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M262.62,-171.54C262.62,-164.19 262.62,-155.71 262.62,-147.63&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;266.12,-147.77 262.62,-137.77 259.12,-147.77 266.12,-147.77&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MAX --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;113.24,-58.4 0,-58.4 0,0 113.24,0 113.24,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;56.62&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Most Frequent&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;56.62&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Traverse struct,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;56.62&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;track max&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;MAX --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;MAX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M210.23,-93.93C186.1,-84.49 156.9,-72.92 123.98,-59.34&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;125.62,-56.23 115.04,-55.64 122.95,-62.7 125.62,-56.23&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- FIRST --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FIRST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;262.19,-58.4 131.05,-58.4 131.05,0 262.19,0 262.19,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.62&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;First Non-Repeat&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.62&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Re-traverse string,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.62&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;check freq==1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;FIRST --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;FIRST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M246.98,-94.29C240.75,-86.36 233.36,-76.96 226.19,-67.83&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;229.01,-65.76 220.08,-60.06 223.51,-70.08 229.01,-65.76&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ANA --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ANA&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;379.25,-58.4 279.99,-58.4 279.99,0 379.25,0 379.25,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;329.62&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Anagram&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;329.62&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Compare two&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;329.62&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;structs&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;ANA --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;ANA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M278.5,-94.29C284.83,-86.36 292.32,-76.96 299.6,-67.83&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;302.31,-70.05 305.81,-60.05 296.84,-65.69 302.31,-70.05&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PRINT --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRINT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;510.24,-58.4 397,-58.4 397,0 510.24,0 510.24,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;453.62&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Print All&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;453.62&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Traverse struct,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;453.62&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;print non-zero&lt;/text&gt;
&lt;/g&gt;
&lt;!-- P2&amp;#45;&amp;gt;PRINT --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;P2-&gt;PRINT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M308.37,-94.08C331.65,-83.84 360.4,-71.2 386.16,-59.87&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;387.49,-63.11 395.24,-55.88 384.67,-56.7 387.49,-63.11&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_two_phase_hashing Pages: 1 --&gt;
&lt;svg width=&quot;325pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 325.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 202.54)&quot;&gt;
&lt;title&gt;semantic_two_phase_hashing&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-202.54 321.26,-202.54 321.26,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;161.48&quot; cy=&quot;-99.11&quot; rx=&quot;88.1&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;161.48&quot; y=&quot;-95.21&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;243.05&quot; cy=&quot;-120.62&quot; rx=&quot;74.21&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;243.05&quot; y=&quot;-117.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Store Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M216.34,-113.58C216.46,-113.61 216.57,-113.64 216.69,-113.67&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;198.01&quot; y=&quot;-116.33&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;120.17&quot; cy=&quot;-25.44&quot; rx=&quot;84.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;120.17&quot; y=&quot;-22.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hashing Retrieval Phase&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M151.27,-80.9C144.91,-69.57 136.77,-55.04 130.41,-43.7&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;150.09&quot; y=&quot;-54.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;88.43&quot; cy=&quot;-141.11&quot; rx=&quot;85.54&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;88.43&quot; y=&quot;-137.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Most Frequent Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M131.35,-116.44C127.1,-118.88 122.74,-121.39 118.5,-123.83&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;145.19&quot; y=&quot;-122.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;204.08&quot; cy=&quot;-171.9&quot; rx=&quot;102.56&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.08&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;First Non-Repeating Character&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M172.01,-117.11C178.52,-128.22 186.84,-142.44 193.37,-153.61&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;202.96&quot; y=&quot;-138.06&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT3 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT3&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;139.95&quot; cy=&quot;-180.54&quot; rx=&quot;68.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.95&quot; y=&quot;-177.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M156.7,-117.18C153.16,-130.58 148.35,-148.78 144.79,-162.24&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;130.48&quot; y=&quot;-142.41&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;80.25&quot; cy=&quot;-76.64&quot; rx=&quot;80.25&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;80.25&quot; y=&quot;-73.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Single-Pass Algorithms&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M108.2,-84.37C108.08,-84.34 107.96,-84.31 107.85,-84.27&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;135.53&quot; y=&quot;-76.22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;234.71&quot; cy=&quot;-56.82&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.71&quot; y=&quot;-53.52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M191.27,-81.91C196.34,-78.98 201.59,-75.95 206.61,-73.05&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;212.7&quot; y=&quot;-80.18&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;183.79&quot; cy=&quot;-18&quot; rx=&quot;91.22&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.79&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M166.55,-80.71C170.2,-67.43 175.1,-49.59 178.75,-36.33&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;165.77&quot; y=&quot;-50.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Universal pattern across all hash-based string problems&lt;/li&gt;
&lt;li&gt;Phase 1 is nearly identical across problems — only the structure type varies&lt;/li&gt;
&lt;li&gt;Phase 2 varies significantly — this is where problem-specific logic lives&lt;/li&gt;
&lt;li&gt;Understanding this separation is the threshold between beginner and intermediate problem-solving&lt;/li&gt;
&lt;li&gt;Enables modular thinking: change Phase 2 without modifying Phase 1&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-store-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-store-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Store Phase&lt;/a&gt; — Phase 1 is the foundation&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hashing-retrieval-phase&quot; class=&quot;internal alias&quot; data-slug=&quot;hashing-retrieval-phase&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hashing Retrieval Phase&lt;/a&gt; — Phase 2 is the query layer&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../most-frequent-character&quot; class=&quot;internal alias&quot; data-slug=&quot;most-frequent-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Most Frequent Character&lt;/a&gt; — uses Phase 1 + Phase 2 (traverse struct for max)&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../first-non-repeating-character&quot; class=&quot;internal alias&quot; data-slug=&quot;first-non-repeating-character&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;First Non-Repeating Character&lt;/a&gt; — uses Phase 1 + Phase 2 (re-traverse string)&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — uses Phase 1 for two strings + Phase 2 (compare)&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../character-hashing-use-cases&quot; class=&quot;internal alias&quot; data-slug=&quot;character-hashing-use-cases&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Character Hashing Use Cases&lt;/a&gt; — catalog of problems following this pattern&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Some problems can be solved in one pass (Phase 1 and 2 interleaved) — the two-phase model is conceptual, not always sequential&lt;/li&gt;
&lt;li&gt;For first non-repeating character, Phase 2 re-traverses the original string, not the hash structure — a common confusion point&lt;/li&gt;
&lt;li&gt;For anagram detection, Phase 1 runs twice (once per string), then Phase 2 compares — the phases apply per-string&lt;/li&gt;
&lt;li&gt;Overlapping Phase 1 and 2 can be more efficient but harder to reason about&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>unordered-map-frequency</title>
    <link href="https://animishraa05.github.io/wiki/strings/unordered-map-frequency" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/strings/unordered-map-frequency.md" />
    <summary>Formal Definition An unordered map (hash map) for frequency counting uses std::unordered_map&amp;lt;Key, int&amp;gt; where each key is an element from the input and the mapped value is its occurrence count.</summary>
    <published>2026-07-03T00:00:00.000Z</published>
    <updated>2026-07-03T00:00:00.000Z</updated>
    <publishedTime>Jul 03, 2026</publishedTime>
    <updatedTime>Jul 03, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="hashing" label="hashing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;An unordered map (hash map) for frequency counting uses &lt;code class=&quot;notranslate&quot;&gt;std::unordered_map&amp;#x3C;Key, int&gt;&lt;/code&gt; where each key is an element from the input and the mapped value is its occurrence count. Unlike a frequency array, the map only stores entries for elements that actually appear, and keys can be of any hashable type.&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;When the character range is unknown, large, or non-contiguous (e.g., mixed case, digits, Unicode), a frequency array becomes impractical. An &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char, int&gt;&lt;/code&gt; stores only the characters that actually appear, with no ASCII math needed — &lt;code class=&quot;notranslate&quot;&gt;freq[ch]&lt;/code&gt; works directly. The tradeoff is hashing overhead, potential collisions, and non-deterministic iteration order.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Declare &lt;code class=&quot;notranslate&quot;&gt;unordered_map&amp;#x3C;char, int&gt; freq&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Iterate through the string: &lt;code class=&quot;notranslate&quot;&gt;for(char ch : s) { freq[ch]++; }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The map automatically creates new key-value pairs for new characters&lt;/li&gt;
&lt;li&gt;To query: iterate key-value pairs or check specific keys&lt;/li&gt;
&lt;li&gt;No conversion needed — character is used as the key directly&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: unordered_map_freq Pages: 1 --&gt;
&lt;svg width=&quot;825pt&quot; height=&quot;50pt&quot; viewBox=&quot;0.00 0.00 825.00 50.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 45.6)&quot;&gt;
&lt;title&gt;unordered_map_freq&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-45.6 821.45,-45.6 821.45,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- INPUT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INPUT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;106.98,-38.8 0,-38.8 0,-2.8 106.98,-2.8 106.98,-38.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;53.49&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Input: &#039;banana&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MAP&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;320.09,-41.6 142.98,-41.6 142.98,0 320.09,0 320.09,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.53&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;unordered_map&amp;#x3C;char,int&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.53&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{} (empty)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INPUT&amp;#45;&amp;gt;MAP --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INPUT-&gt;MAP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M107.31,-20.8C114.97,-20.8 123.05,-20.8 131.27,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;131.02,-24.3 141.02,-20.8 131.02,-17.3 131.02,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- B --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;B&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;433.48,-41.6 356.09,-41.6 356.09,0 433.48,0 433.48,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;394.78&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[&#039;b&#039;]++&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;394.78&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{b:1}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MAP&amp;#45;&amp;gt;B --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MAP-&gt;B&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M320.24,-20.8C328.48,-20.8 336.62,-20.8 344.31,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;344.09,-24.3 354.09,-20.8 344.09,-17.3 344.09,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- A --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;A&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;546.86,-41.6 469.48,-41.6 469.48,0 546.86,0 546.86,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;508.17&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[&#039;a&#039;]++&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;508.17&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:1, b:1}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- B&amp;#45;&amp;gt;A --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;B-&gt;A&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M433.8,-20.8C441.6,-20.8 449.91,-20.8 458.03,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;457.81,-24.3 467.81,-20.8 457.81,-17.3 457.81,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- N --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;N&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;682.16,-41.6 582.86,-41.6 582.86,0 682.16,0 682.16,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;632.51&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;freq[&#039;n&#039;]++&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;632.51&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:1, b:1, n:1}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A&amp;#45;&amp;gt;N --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;A-&gt;N&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M547.21,-20.8C554.84,-20.8 563.03,-20.8 571.2,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;571.16,-24.3 581.16,-20.8 571.16,-17.3 571.16,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- FINAL --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FINAL&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;817.45,-41.6 718.16,-41.6 718.16,0 817.45,0 817.45,-41.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;767.81&quot; y=&quot;-25&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;Final:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;767.81&quot; y=&quot;-8.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;14.00&quot;&gt;{a:3, b:1, n:2}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- N&amp;#45;&amp;gt;FINAL --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;N-&gt;FINAL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M682.39,-20.8C690.27,-20.8 698.5,-20.8 706.61,-20.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;706.42,-24.3 716.42,-20.8 706.42,-17.3 706.42,-24.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_unordered_map Pages: 1 --&gt;
&lt;svg width=&quot;317pt&quot; height=&quot;207pt&quot; viewBox=&quot;0.00 0.00 317.00 207.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 203.13)&quot;&gt;
&lt;title&gt;semantic_unordered_map&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-203.13 313.48,-203.13 313.48,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;155.08&quot; cy=&quot;-99.52&quot; rx=&quot;113.46&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;155.08&quot; y=&quot;-95.62&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Unordered Map Frequency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE1&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;238.69&quot; cy=&quot;-100.14&quot; rx=&quot;70.79&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;238.69&quot; y=&quot;-96.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Map Flexibility&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M238.63,-100.14C238.65,-100.14 238.67,-100.14 238.68,-100.14&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.15&quot; y=&quot;-102.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE2&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;137.16&quot; cy=&quot;-18&quot; rx=&quot;85.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;137.16&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Hash Collision Overhead&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;PRE2 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--PRE2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M151.1,-81.43C148.16,-68.01 144.15,-49.79 141.19,-36.32&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.65&quot; y=&quot;-61.58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT1&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;80.15&quot; cy=&quot;-136.37&quot; rx=&quot;71.17&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;80.15&quot; y=&quot;-133.07&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Two-Phase Hashing&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M119.37,-117.08C117.26,-118.12 115.14,-119.16 113.04,-120.2&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;136.47&quot; y=&quot;-121.34&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- OUT2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OUT2&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;207.28&quot; cy=&quot;-164.83&quot; rx=&quot;68.15&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;207.28&quot; y=&quot;-161.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Anagram Detection&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;OUT2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--OUT2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.62,-117.71C176.98,-126.92 185.88,-138.06 193.18,-147.19&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;201.66&quot; y=&quot;-135.15&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CON1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CON1&lt;/title&gt;
&lt;ellipse fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; cx=&quot;137.12&quot; cy=&quot;-181.13&quot; rx=&quot;60.2&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;137.12&quot; y=&quot;-177.83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Frequency Array&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;CON1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--CON1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M151.09,-117.63C148.14,-131.06 144.13,-149.3 141.16,-162.79&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;173.64&quot; y=&quot;-132.11&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;contrasts with&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL1&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;79.87&quot; cy=&quot;-63.33&quot; rx=&quot;79.87&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;79.87&quot; y=&quot;-60.03&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;ASCII Math Elimination&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL1 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M118.8,-82.06C117.29,-81.34 115.79,-80.62 114.29,-79.89&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;130.3&quot; y=&quot;-83.68&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REL2 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REL2&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;207.89&quot; cy=&quot;-34.8&quot; rx=&quot;77.98&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;207.89&quot; y=&quot;-31.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Map Traversal Method&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;REL2 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--REL2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.79,-81.49C177.12,-72.51 185.95,-61.69 193.26,-52.73&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;195.29&quot; y=&quot;-69.81&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Average O(1) insertion and lookup (amortized, may degrade to O(n) with collisions)&lt;/li&gt;
&lt;li&gt;Only stores distinct elements — memory proportional to unique characters, not domain size&lt;/li&gt;
&lt;li&gt;Keys can be any hashable type: &lt;code class=&quot;notranslate&quot;&gt;char&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;string&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;int&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;long long&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;No &lt;code class=&quot;notranslate&quot;&gt;ch - &#039;a&#039;&lt;/code&gt; conversion needed — eliminates ASCII math entirely&lt;/li&gt;
&lt;li&gt;Iteration order is unspecified and non-deterministic&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-map-flexibility&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-map-flexibility&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Map Flexibility&lt;/a&gt; — unordered_map supports diverse key types&lt;/li&gt;
&lt;li&gt;Built from: &lt;a href=&quot;../../hash-collision-overhead&quot; class=&quot;internal alias&quot; data-slug=&quot;hash-collision-overhead&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hash Collision Overhead&lt;/a&gt; — the performance tradeoff of hash maps&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../two-phase-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;two-phase-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Two-Phase Hashing Paradigm&lt;/a&gt; — maps are one implementation choice for Phase 1&lt;/li&gt;
&lt;li&gt;Builds into: &lt;a href=&quot;../../anagram-detection-via-hashing&quot; class=&quot;internal alias&quot; data-slug=&quot;anagram-detection-via-hashing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Anagram Detection&lt;/a&gt; — maps are ideal when character set is unknown&lt;/li&gt;
&lt;li&gt;Contrasts with: &lt;a href=&quot;../../frequency-array&quot; class=&quot;internal alias&quot; data-slug=&quot;frequency-array&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Frequency Array&lt;/a&gt; — array is faster for small known ranges; map is more flexible&lt;/li&gt;
&lt;li&gt;Related: &lt;a href=&quot;../../ascii-math-elimination&quot; class=&quot;internal alias&quot; data-slug=&quot;ascii-math-elimination&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;ASCII Math Elimination&lt;/a&gt; — maps eliminate the need for index conversion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;code class=&quot;notranslate&quot;&gt;freq[ch]++&lt;/code&gt; creates an entry with value 0 if the key does not exist, then increments — no manual insertion needed&lt;/li&gt;
&lt;li&gt;Repeated insertions may trigger rehashing, which is O(n) amortized but can be a latency spike&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;notranslate&quot;&gt;unordered_map&lt;/code&gt; is not ordered — if you need sorted output, use &lt;code class=&quot;notranslate&quot;&gt;map&lt;/code&gt; (O(log n) per operation) or sort the result&lt;/li&gt;
&lt;li&gt;For small datasets (like lowercase-only strings), a map is slower than a frequency array despite both being O(1) — the constant factors matter&lt;/li&gt;
&lt;li&gt;Memory per entry is higher than an array slot due to key storage, hash table overhead, and pointer chains&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
</feed>