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

Complexity analysis docs
Complexity analysis
Complexity Analysis ConceptsHow It Works: From Counting Operations to the Master TheoremImplementation: Measuring Three Growth RatesComplexity: Common Classes, Amortized Cost and SpacePractice ProblemsReal-World Use
Discussions

Complexity analysis guide · 6/6

Real-World Use

Complexity analysis is not just for exams. It is what you reach for when deciding whether a service survives ten times more data, which data structure to use, and where a slowdown comes from. This chapter shows where complexity surfaces in real systems, the usual traps, and where to read further.

Know the cost of your standard library

The same task can have a different complexity depending on the data structure. Common Python costs:

Operationlistdict / setcollections.deque
Append at the endO(1) amortizedO(1) averageO(1)
Insert/remove at the frontO(n)n/aO(1)
Membership (in)O(n)O(1) averageO(n)
Index accessO(1)n/aO(1) at the ends, O(n) in the middle
Sorting (sorted)O(n log n)n/an/a

A queue built on a list with repeated pop(0) shifts every remaining element each time, so draining it is O(n²). deque.popleft() makes it O(n).

from collections import deque

def drain_list(n):
    q = list(range(n))
    while q:
        q.pop(0)          # O(n) each time

def drain_deque(n):
    q = deque(range(n))
    while q:
        q.popleft()       # O(1)

Databases and indexes

Searching on a column without an index makes the database scan the whole table (O(n)). A B-tree index brings lookups down to O(log n), at the cost of extra storage and work on every write. When a query plan (EXPLAIN) shows a full scan, that is the first place to look.

The N+1 query problem in application code is the same issue. Fetching n rows and then sending one more query per row means n round trips, even if each one is fast. A join or a single IN (...) query makes the number of round trips constant.

# N+1: one query per user
for user in users:
    orders = db.query("SELECT * FROM orders WHERE user_id = ?", user.id)

# batched: one query
ids = [user.id for user in users]
placeholders = ", ".join("?" * len(ids))
orders = db.query(f"SELECT * FROM orders WHERE user_id IN ({placeholders})", *ids)

When average and worst case differ: hashing and regex

A hash table's O(1) is an average. If many keys land in the same bucket, operations degrade to O(n). Hash flooding attacks have exploited this by sending deliberately colliding keys, which is why Python mixes a per-process random seed into string hashes and Java's HashMap turns crowded buckets into balanced trees.

Regular expressions have the same trap. In a backtracking engine, a pattern like (a+)+$ can try exponentially many ways to fail on a non-matching input and stall a server (ReDoS). For patterns that see user input, avoid nested quantifiers and cap the input length.

import re
import time

pattern = re.compile(r"(a+)+$")
for n in (18, 20, 22):
    text = "a" * n + "!"
    start = time.perf_counter()
    pattern.match(text)
    print(n, f"{time.perf_counter() - start:.3f}s")   # about 4x for every 2 extra characters

Common pitfalls

  • Ignoring constants on small inputs: for a few dozen elements, O(n²) insertion sort can beat an O(n log n) sort. That is why real sort routines (Timsort, introsort) switch to insertion sort for short runs.
  • Ignoring the memory hierarchy: two O(n) loops can differ several times in speed because a sequential array scan is cache-friendly and pointer chasing through a linked list is not.
  • Building strings by repeated concatenation: depending on the language and implementation this can be O(n²); collect pieces and use "".join(parts).
  • Guessing instead of measuring: bottlenecks are often somewhere unexpected. Profile first, for example with cProfile.

Further reading

  • Big O notation (Wikipedia)
  • Master theorem (Wikipedia)
  • Amortized analysis (Wikipedia)
  • TimeComplexity (Python Wiki)
  • timeit (Python documentation)
  • The Python Profilers (Python documentation)
  • MIT OpenCourseWare 6.006 Introduction to Algorithms
  • Regular expression Denial of Service (OWASP)

Summary

  • Knowing standard library costs helps you avoid hidden O(n) operations such as pop(0) and in list.
  • Many real performance fixes, like indexes and batched queries, drop the complexity by one class.
  • Where average and worst case differ, attacks or unusual inputs can trigger the worst case.
  • Complexity is the starting point; measure to see constants and memory effects.
Questions about this chapter?
Previous chapterPractice Problems

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.