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 · 5/6

Practice Problems

Per ora questo capitolo è disponibile solo in inglese.

Most graph problems are half solved the moment you decide what the vertices and edges are. The four problems below were written for this guide and mirror patterns that come up often in coding interviews. Try each one before reading the solution.

Problem 1. Warehouse robot

A warehouse map is given as a list of strings. S is the robot's start, E the target, # a shelf (blocked) and . an empty cell. The robot moves one cell up, down, left or right per step. Return the minimum number of steps to reach the target, or -1 if it cannot.

Approach: cells are vertices and adjacent open cells share an edge. Every move costs 1, so the distance at which BFS first reaches E is the answer.

from collections import deque

def min_steps(grid):
    rows, cols = len(grid), len(grid[0])
    start = next((r, c) for r in range(rows) for c in range(cols) if grid[r][c] == "S")
    dist = {start: 0}
    queue = deque([start])
    while queue:
        r, c = queue.popleft()
        if grid[r][c] == "E":
            return dist[(r, c)]
        for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            nr, nc = r + dr, c + dc
            if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] != "#" and (nr, nc) not in dist:
                dist[(nr, nc)] = dist[(r, c)] + 1
                queue.append((nr, nc))
    return -1

print(min_steps(["S.#.", "..#E", "...."]))  # 6

The shelves force a detour through the bottom row, so the answer is 6 rather than the Manhattan distance of 4.

Problem 2. Server clusters

You have n servers and a list of cables (a, b). Servers linked directly or indirectly form one cluster. Return the number of clusters and the size of the largest one.

Approach: this is connected components. Start a traversal from every unvisited server and count how many servers it reaches. An explicit stack avoids the recursion limit.

def server_groups(n, cables):
    adj = [[] for _ in range(n)]
    for a, b in cables:
        adj[a].append(b)
        adj[b].append(a)
    seen = [False] * n
    groups, largest = 0, 0
    for s in range(n):
        if seen[s]:
            continue
        groups += 1
        seen[s] = True
        stack, size = [s], 0
        while stack:
            u = stack.pop()
            size += 1
            for v in adj[u]:
                if not seen[v]:
                    seen[v] = True
                    stack.append(v)
        largest = max(largest, size)
    return groups, largest

print(server_groups(7, [(0, 1), (1, 2), (3, 4)]))  # (4, 3)

Problem 3. Module build order

A dictionary maps each module to the modules that must be built before it. Return an order that builds everything; when several modules are ready at once, pick the alphabetically smallest. Return if there is a circular dependency.

Domande su questo capitolo?
Capitolo precedenteComplexityCapitolo successivoReal-World Use
None

Approach: "A before B" is an edge A→B, so this is a topological sort. Replacing Kahn's queue with a heap always yields the smallest ready name.

import heapq

def build_order(deps):
    indeg = {m: 0 for m in deps}
    users = {m: [] for m in deps}
    for module, needs in deps.items():
        for need in needs:
            users[need].append(module)
            indeg[module] += 1
    ready = [m for m, d in indeg.items() if d == 0]
    heapq.heapify(ready)
    order = []
    while ready:
        m = heapq.heappop(ready)
        order.append(m)
        for user in users[m]:
            indeg[user] -= 1
            if indeg[user] == 0:
                heapq.heappush(ready, user)
    return order if len(order) == len(deps) else None

deps = {"app": ["ui", "net"], "ui": ["core"], "net": ["core"], "core": [], "log": []}
print(build_order(deps))                      # ['core', 'log', 'net', 'ui', 'app']
print(build_order({"a": ["b"], "b": ["a"]}))  # None

The heap makes it O((V + E) log V). If any valid order will do, a plain deque is enough.

Problem 4. Spreading signal

A grid contains several relays R. Every minute the signal spreads from each covered cell to adjacent empty cells .; # is a wall. Return how many minutes it takes to cover every empty cell, or -1 if some cell is never reached.

Approach: this is multi-source BFS. Enqueue every R at distance 0 before starting, and each cell's distance becomes its distance to the nearest relay. Running a separate BFS per relay would be far slower.

from collections import deque

def spread_time(grid):
    rows, cols = len(grid), len(grid[0])
    dist = [[-1] * cols for _ in range(rows)]
    queue = deque()
    for r in range(rows):
        for c in range(cols):
            if grid[r][c] == "R":
                dist[r][c] = 0
                queue.append((r, c))
    while queue:
        r, c = queue.popleft()
        for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            nr, nc = r + dr, c + dc
            if 0 <= nr < rows and 0 <= nc < cols and grid[nr][nc] == "." and dist[nr][nc] == -1:
                dist[nr][nc] = dist[r][c] + 1
                queue.append((nr, nc))
    cells = [dist[r][c] for r in range(rows) for c in range(cols) if grid[r][c] == "."]
    return -1 if -1 in cells else max(cells, default=0)

print(spread_time(["R..#", "...#", "#..R"]))  # 2

Summary

Grid shortest paths map to BFS, counting groups to connected components, ordering to topological sort, and many starting points to multi-source BFS. Before coding, write down what the vertices and edges are, whether edges are weighted, and whether they are directed; that habit solves more problems than any trick.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.