<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Data Structure and Algorithm - Category - MartinLwx&#39;s Blog</title>
        <link>https://martinlwx.github.io/en/categories/data-structure-and-algorithm/</link>
        <description>Data Structure and Algorithm - Category - MartinLwx&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>martinlwx@163.com (MartinLwx)</managingEditor>
            <webMaster>martinlwx@163.com (MartinLwx)</webMaster><copyright>&lt;a rel=&#34;license noopener&#34; href=&#34;https://creativecommons.org/licenses/by-nc-nd/4.0/&#34; target=&#34;_blank&#34;&gt;CC BY-NC-ND 4.0&lt;/a&gt;</copyright><lastBuildDate>Fri, 08 May 2026 20:56:00 &#43;0800</lastBuildDate><atom:link href="https://martinlwx.github.io/en/categories/data-structure-and-algorithm/" rel="self" type="application/rss+xml" /><item>
    <title>Dynamic Time Warping: From Euclidean Distance to Optimal Alignment</title>
    <link>https://martinlwx.github.io/en/dynamic-time-warping/</link>
    <pubDate>Fri, 08 May 2026 20:56:00 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/en/dynamic-time-warping/</guid>
    <description><![CDATA[<div class="details admonition note open">
    <div class="details-summary admonition-title">
        <span class="icon"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M497.9 142.1l-46.1 46.1c-4.7 4.7-12.3 4.7-17 0l-111-111c-4.7-4.7-4.7-12.3 0-17l46.1-46.1c18.7-18.7 49.1-18.7 67.9 0l60.1 60.1c18.8 18.7 18.8 49.1 0 67.9zM284.2 99.8L21.6 362.4.4 483.9c-2.9 16.4 11.4 30.6 27.8 27.8l121.5-21.3 262.6-262.6c4.7-4.7 4.7-12.3 0-17l-111-111c-4.8-4.7-12.4-4.7-17.1 0zM124.1 339.9c-5.5-5.5-5.5-14.3 0-19.8l154-154c5.5-5.5 14.3-5.5 19.8 0s5.5 14.3 0 19.8l-154 154c-5.5 5.5-14.3 5.5-19.8 0zM88 424h48v36.3l-64.5 11.3-31.1-31.1L51.7 376H88v48z"/></svg></span>Note<span class="details-icon"><svg class="icon"
    xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"/></svg></span>
    </div>
    <div class="details-content">
        <div class="admonition-content"><p>You can find the code demo <a href="https://github.com/MartinLwx/blog-demos/blob/main/data_analysis/dtw/dtw.ipynb" target="_blank" rel="noopener noreferrer">here</a></p>]]></description>
</item><item>
    <title>Suffix array: find the needle in the hay</title>
    <link>https://martinlwx.github.io/en/suffix-array-tutorial/</link>
    <pubDate>Sun, 11 Jan 2026 22:23:22 &#43;0800</pubDate><author>
        <name>MartinLwx</name>
    </author><guid>https://martinlwx.github.io/en/suffix-array-tutorial/</guid>
    <description><![CDATA[<h2 id="suffix-array" class="headerLink">
    <a href="#suffix-array" class="header-mark"></a>Suffix array</h2><p>By definition, a suffix array (denoted as <code>sa</code>) contains the starting indices of all suffixes. It&rsquo;s simply an <code>int</code> array where <code>sa[i]</code> represents the starting index of the corresponding suffix.</p>
<p>Taking <code>fizzbuzz</code> as an example, its suffix array is <code>4 0 1 5 7 3 6 2</code>. The details are shown in the following table.</p>
<table>
  <thead>
      <tr>
          <th>Suffix array <code>sa</code></th>
          <th>Corresponding suffix</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>4</td>
          <td><code>buzz</code></td>
      </tr>
      <tr>
          <td>0</td>
          <td><code>fizzbuzz</code></td>
      </tr>
      <tr>
          <td>1</td>
          <td><code>izzbuzz</code></td>
      </tr>
      <tr>
          <td>5</td>
          <td><code>uzz</code></td>
      </tr>
      <tr>
          <td>7</td>
          <td><code>z</code></td>
      </tr>
      <tr>
          <td>3</td>
          <td><code>zbuzz</code></td>
      </tr>
      <tr>
          <td>6</td>
          <td><code>zz</code></td>
      </tr>
      <tr>
          <td>2</td>
          <td><code>zzbuzz</code></td>
      </tr>
  </tbody>
</table>
<h2 id="how-to-generate-a-suffix-array" class="headerLink">
    <a href="#how-to-generate-a-suffix-array" class="header-mark"></a>How to generate a suffix array</h2><h3 id="naive-way" class="headerLink">
    <a href="#naive-way" class="header-mark"></a>Naive way</h3><p>Let $N$ represent the length of the string. The naive algorithm is straightforward: generate all possible suffixes and then sort them using an efficient sorting algorithm. This requires one sort iteration, which may involve $O(N log\ N)$ comparisons. In the worst case, each string comparison takes $O(N)$ time. Therefore, the overall time complexity would be</p>]]></description>
</item></channel>
</rss>
