Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

Developer docs
String algorithms
String algorithmsReference implementationStep-by-step guideOfficial docs and resourcesDiscussionsComments

Other algorithms

Algorithm basics5
Complexity analysisSortingSearchingBasic data structuresTrees and heaps
Core algorithms6
Graph traversalShortest paths & minimum spanning treesDynamic programmingGreedy algorithmsDivide and conquerBacktracking
Advanced algorithms4
Math and number theoryBit manipulationSegment treesUnion-find
Practical algorithms4
Coding interview strategyLRU cacheRate limitingConsistent hashing

Algorithm

String algorithms

String algorithms find patterns in text and look up words by prefix; KMP, Rabin-Karp, tries and the Z-algorithm are the core techniques.

Start the guideDiscussions

String algorithms are methods for comparing and searching sequences of characters quickly and correctly. The central problem is pattern matching, finding every place a short pattern occurs in a long text, but looking up all dictionary words with a given prefix and finding many patterns at once belong here too. The naive approach of checking every position can take time proportional to the text length times the pattern length.

Find-in-file, log search, search-box autocomplete, intrusion detection, file synchronization and genome analysis all run on string algorithms. KMP reuses earlier comparisons through a failure table to guarantee linear time, Rabin-Karp slides a rolling hash across the text to avoid most comparisons, and a trie shares common prefixes so that prefix lookups cost time proportional only to the word length. The topic also comes up often in coding interviews.

Start with the vocabulary of prefixes, suffixes and borders, and see by hand why naive matching is slow. Then compute a prefix-function table for a small pattern yourself, implement KMP search and a trie, and check them against the standard library. Finally, look at the pitfalls that make real-world results wrong, such as hash collisions and Unicode normalization.

On this page

  1. Highlights
  2. Where it is used
  3. Reference implementation
  4. Step-by-step guide
  5. Official docs and resources
  6. Discussions
  7. Comments

Highlights

Prefix function and KMP

Precompute the longest border of every pattern prefix; on a mismatch, fall back to a shorter border instead of rewinding the text, giving O(n + m) search.

Rolling hash

Rabin-Karp updates the hash of each length-m window in O(1), compares it with the pattern hash and checks the characters only when the hashes match.

Tries

A tree you walk down character by character; shared prefixes are stored once, so prefix lookup and autocomplete take time proportional to the word length.

Z-algorithm and Unicode

The Z-array gives, for every position, the longest common prefix with the whole string in linear time. Real text also requires care with normalization and index units.

Where it is used

  • Find-in-file and log search
  • Autocomplete and dictionaries
  • Intrusion detection and word filters
  • File sync and genome sequence analysis

Reference implementation

Reference implementation: KMP search

prefix_function computes the longest border of every prefix of the pattern, and kmp_search uses that table to read the text once, left to right, collecting every start position. Because k is reset to pi[k - 1] after a match, overlapping occurrences such as those at 0 and 2 are found as well. Run python string_search.py to print both results.

string_search.py

def prefix_function(p: str) -> list[int]:
    """pi[i] = length of the longest proper border of p[:i + 1]."""
    pi = [0] * len(p)
    k = 0
    for i in range(1, len(p)):
        while k > 0 and p[i] != p[k]:
            k = pi[k - 1]
        if p[i] == p[k]:
            k += 1
        pi[i] = k
    return pi


def kmp_search(text: str, pattern: str) -> list[int]:
    """Start positions of every (possibly overlapping) occurrence."""
    if not pattern:
        return list(range(len(text) + 1))
    pi = prefix_function(pattern)
    hits, k = [], 0
    for i, ch in enumerate(text):
        while k > 0 and ch != pattern[k]:
            k = pi[k - 1]
        if ch == pattern[k]:
            k += 1
        if k == len(pattern):
            hits.append(i - k + 1)
            k = pi[k - 1]
    return hits


if __name__ == "__main__":
    print(prefix_function("ababaca"))         # [0, 0, 1, 2, 3, 0, 1]
    print(kmp_search("abababcabab", "abab"))  # [0, 2, 7]
python string_search.py

Step-by-step guide

Six chapters that take you from installation to the core ideas of String algorithms.

  1. Concepts
  2. How It Works
  3. Implementation
  4. Complexity
  5. Practice Problems
  6. Real-World Use

Official docs and resources

  • OfficialPython String Methods
  • OfficialUnicode HOWTO
  • LearnPrefix function. Knuth–Morris–Pratt
  • LearnZ-function and its calculation
  • LearnString Hashing
  • ReferenceString-searching algorithm
  • ReferenceKnuth–Morris–Pratt algorithm
  • ReferenceTrie

Discussions

Start a discussion

Ask questions, share experience and trade opinions about String algorithms.

No discussions yet. Start the first one.

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.