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

Graph traversal docs
Graph traversal
Graph Traversal ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
Discussions

Graph traversal guide · 1/6

Graph Traversal Concepts

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.

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.

Questions about this chapter?
Next chapterHow It Works

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.