Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Ricerca
Ricerca
Searching ConceptsHow It WorksImplementationComplexityPractice ProblemsSearching in the Real World
Discussioni

Guida a Ricerca · 4/6

Complexity

Per ora questo capitolo è disponibile solo in inglese.

Choosing a search method is not only about the cost of one lookup. You also have to weigh the cost of preparing the data, the cost of updates, memory use, and which kinds of questions the structure can answer at all. This chapter lays out the costs of linear search, binary search, parametric search, ternary search and hash lookup, and turns them into rules for picking one.

Linear search

  • Best case: the first element matches, one comparison, O(1).
  • Average case: with the target equally likely anywhere, about n / 2 comparisons, O(n).
  • Worst case: the target is last or missing, n comparisons, O(n).
  • Space: O(1) extra memory.

It needs no preparation and works on unsorted data. Because it reads contiguous memory in order, which caches love, it often beats binary search in practice for a few dozen elements or fewer.

Binary search

Each comparison halves the range, so the worst case is floor(log2 n) + 1 comparisons: 20 for a million elements, 30 for a billion.

  • Time: best O(1) (the closed-interval form can hit the target at the first midpoint), average and worst O(log n). The lower_bound form always runs close to log n steps.
  • Space: O(1) for the loop version, O(log n) for a recursive version because of the call stack.
  • Precondition: the data must be sorted, and sorting costs O(n log n).

Counting the steps makes the logarithmic growth visible.

def lower_bound_count(a, x):
    lo, hi, steps = 0, len(a), 0
    while lo < hi:
        steps += 1
        mid = (lo + hi) // 2
        if a[mid] < x:
            lo = mid + 1
        else:
            hi = mid
    return lo, steps


for n in (10, 1_000, 1_000_000):
    a = list(range(n))
    print(n, lower_bound_count(a, n - 1)[1])   # 3, 10, 20

When does sorting pay off?

With k queries, linear search costs k * n while sort-then-search costs n log n + k log n. Once the number of queries is well above log n, sorting wins. If you will search a dataset once or twice and then throw it away, do not sort it.

Inserting into or deleting from a sorted array means shifting the elements behind the position, which is O(n). When updates are frequent, a balanced binary search tree, a B-tree, or a library such as Python's sortedcontainers keeps both lookups and updates near O(log n).

Parametric and ternary search

If the answer range has size R and evaluating the predicate costs , parametric search costs . A predicate that scans the whole array to test feasibility gives . On real numbers, run iterations for a precision , or simply a fixed count such as 100.

Domande su questo capitolo?
Capitolo precedenteImplementationCapitolo successivoPractice Problems
C
O(C * log R)
O(n log R)
log2(R / eps)
eps

Ternary search keeps two thirds of the range per round and evaluates the function twice each time. For the same precision it therefore needs more evaluations than binary search. If the problem is on integers and can be rewritten as a neighbor-comparison binary search, prefer that.

import math

R, eps = 1e9, 1e-6
print(math.ceil(math.log2(R / eps)))            # binary: about 50 rounds, 50 evaluations
print(math.ceil(math.log(R / eps, 1.5)) * 2)    # ternary: about 86 rounds, about 172 evaluations

Hash lookup

A hash table finds a key in O(1) on average, but if every key lands in the same bucket the worst case degrades to O(n). It also uses more memory than an array, and since it keeps no order it cannot answer range queries, "next larger value", or "k-th smallest".

import random
import timeit
from bisect import bisect_left

data = sorted(random.sample(range(10_000_000), 100_000))
as_set = set(data)
probe = data[len(data) // 2]

print(timeit.timeit(lambda: probe in data, number=200))     # linear: slowest
print(timeit.timeit(lambda: bisect_left(data, probe), number=200))
print(timeit.timeit(lambda: probe in as_set, number=200))   # hash: fastest

The exact numbers depend on your machine, but with 100,000 elements linear search is typically thousands of times slower than the other two, or worse.

Comparison table

MethodPreparationOne lookupInsert / deleteRange and order queriesExtra memory
Linear searchnoneO(n)O(1) (append)possible, but O(n)O(1)
Sorted array + binary searchO(n log n)O(log n)O(n)O(log n + k)O(1)
Balanced BST / B-treeO(n log n)O(log n)O(log n)O(log n + k)O(n)
Hash tableO(n)O(1) averageO(1) averagenot supportedO(n)

Here k is the number of results that fall inside the range.

Summary

  • Linear search is O(n) but needs no preparation, which suits small data and one-off lookups.
  • Binary search is O(log n); the O(n log n) sorting cost is recovered when there are many queries.
  • Parametric search costs O(predicate cost * log range); ternary search needs more evaluations for the same precision.
  • Use a hash for exact matches; use a sorted array or a tree when you need ranges or order.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.