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 Visita dei grafi
Visita dei grafi
Graph Traversal ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
Discussioni

Guida a Visita dei grafi · 1/6

Graph Traversal Concepts

Per ora questo capitolo è disponibile solo in inglese.

Graph traversal means visiting every vertex reachable from a starting point, each exactly once, by following edges. Maps, social networks, task dependencies and mazes are all questions of "what is connected to what", and most of them are solved with a traversal. This chapter covers the vocabulary, how to store a graph in code, and the intuition behind the two classic traversals: breadth-first search (BFS) and depth-first search (DFS).

Vocabulary

TermMeaning
Vertex (node)A point in the graph: a city, a person, a task, a grid cell
EdgeA connection between two vertices: a road, a friendship, a dependency
Directed graphEdges have a direction; A→B does not imply B→A
Undirected graphEvery edge works both ways
DegreeNumber of edges touching a vertex; in-degree and out-degree for directed graphs
PathA sequence of vertices joined by edges
CycleA path that returns to its starting vertex
Connected componentA maximal group of vertices that can all reach each other
DAGDirected Acyclic Graph: a directed graph with no cycles

By convention V is the number of vertices and E the number of edges. Graph algorithm costs are almost always written in terms of these two.

Storing a graph

The default choice is an adjacency list: each vertex keeps a list of its neighbors. It uses O(V + E) memory, and iterating over a vertex's neighbors costs only as much as it has neighbors.

from collections import defaultdict

edges = [(0, 1), (0, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)]

graph = defaultdict(list)
for u, v in edges:
    graph[u].append(v)
    graph[v].append(u)  # undirected: add the reverse edge too

print(graph[2])  # [0, 3, 4]

An adjacency matrix is a V x V table of 0s and 1s. It answers "is there an edge between u and v?" in O(1), but needs O(V^2) memory, which is wasteful for sparse graphs with many vertices and few edges.

n = 6
matrix = [[0] * n for _ in range(n)]
for u, v in edges:
    matrix[u][v] = matrix[v][u] = 1

print(matrix[2][4] == 1)  # True: 2 and 4 are neighbors

A plain edge list (the edges variable itself) is also a representation. It suits algorithms that sort edges, such as Kruskal's, but finding neighbors means scanning everything, so for traversal you convert it into an adjacency list first.

Domande su questo capitolo?
Capitolo successivoHow It Works

Directions and vertex ids

For a directed graph, add only u→v. When vertices are strings (city names, module names), either use a dictionary or map each name to an integer id and use a list of lists, which is faster and lighter. If the input numbers vertices from 1, size your lists n + 1 or subtract 1 from every id to avoid index errors.

names = ["core", "ui", "app"]
index = {name: i for i, name in enumerate(names)}
adj = [[] for _ in names]
for before, after in [("core", "ui"), ("ui", "app")]:
    adj[index[before]].append(index[after])   # one direction only

print(adj)  # [[1], [2], []]

Grids are graphs too

Mazes and maps given as 2D grids become graphs once you treat each cell as a vertex and connect cells that touch up, down, left or right. These are usually handled as implicit graphs: instead of building an adjacency list, you compute neighbors on the fly.

DIRS = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def neighbors(grid, r, c):
    rows, cols = len(grid), len(grid[0])
    for dr, dc in DIRS:
        nr, nc = r + dr, c + dc
        if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] != "#":
            yield nr, nc

BFS and DFS in one picture

  • BFS (breadth-first search) expands outward one layer at a time, nearest vertices first, using a queue. In a graph where every edge has the same cost, it finds shortest paths (fewest edges).
  • DFS (depth-first search) goes as deep as it can along one branch, then backtracks, using recursion or an explicit stack. It is the backbone of connected components, cycle detection, topological sorting and backtracking.

Both depend on a visited marker. Never revisiting a vertex is what makes traversal terminate on graphs with cycles and keeps the total cost at O(V + E).

Which one to use

QuestionTool
Fewest moves from A to B (no weights)BFS
Are two vertices connected? How many groups?BFS or DFS
Does the graph contain a cycle?DFS with colors, or Kahn's algorithm
An order that respects dependenciesTopological sort (Kahn or DFS)
Shortest path with different edge weightsDijkstra and friends (see Shortest paths)

Summary

A graph models relationships with vertices and edges, and traversal follows edges while marking what it has seen. An adjacency list is the default representation, and grids are best treated as implicit graphs. BFS, which grows outward layer by layer, gives unweighted shortest distances; DFS, which dives deep first, is the tool for structure: components, cycles and topological order.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.