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

Developer docs
Graph traversal
Graph traversalReference implementationStep-by-step guideOfficial docs and resourcesDiscussionsComments

Other algorithms

Algorithm basics5
Complexity analysisSortingSearchingBasic data structuresTrees and heaps
Core algorithms5
Shortest paths & minimum spanning treesDynamic programmingGreedy algorithmsDivide and conquerBacktracking
Advanced algorithms5
String algorithmsMath and number theoryBit manipulationSegment treesUnion-find
Practical algorithms4
Coding interview strategyLRU cacheRate limitingConsistent hashing

Algorithm

Graph traversal

Graph traversal visits every reachable vertex with BFS or DFS, the basis for unweighted shortest paths, components, cycle detection and topological sorting.

Start the guideDiscussions

Graph traversal is the process of visiting every vertex reachable from a starting vertex exactly once by following edges. The two fundamental strategies are breadth-first search (BFS), which uses a queue to expand outward one layer at a time, and depth-first search (DFS), which uses a stack or recursion to follow one branch as far as possible before backtracking. Graphs are usually stored as adjacency lists or adjacency matrices, and 2D grids such as mazes become graphs once each cell is treated as a vertex.

Road networks, social networks, task dependencies and web links are all graphs. BFS finds shortest paths when every edge has the same cost, while DFS underpins connected components, cycle detection and topological sorting. Build tools ordering their tasks, garbage collectors deciding what is still reachable and the paint-bucket tool in an image editor all rely on traversal, and it is one of the most common topics in coding interviews.

Start by drawing a small graph and tracing by hand how the BFS queue and the DFS call stack evolve. Then implement both yourself, paying attention to when vertices are marked as visited and how distances and parents are recorded. From there, move on to grid shortest paths, counting connected components and topological sorting with Kahn's algorithm.

On this page

  1. Highlights
  2. Where it is used
  3. Reference implementation
  4. Step-by-step guide
  5. Official docs and resources
  6. Discussions
  7. Comments

Highlights

Graph representations

Adjacency lists use O(V + E) memory and suit sparse graphs; adjacency matrices check edges in O(1) but need O(V^2) memory.

Breadth-first search

A queue visits the nearest vertices first, so in an unweighted graph the first distance BFS assigns is the shortest one.

Depth-first search

Recursion or a stack dives deep and backtracks, forming the basis of components, cycle detection and backtracking.

Topological sorting

In a directed acyclic graph, Kahn's algorithm or reversed DFS finish order yields an order that respects every dependency.

Where it is used

  • Shortest moves through mazes and grid maps
  • Dependency ordering in build systems and package managers
  • Finding connected groups and degrees of separation in social networks
  • Marking reachable objects in garbage collectors

Reference implementation

BFS and DFS side by side

The program builds a six-vertex undirected graph as a dictionary-based adjacency list, then prints the fewest edges from A to every vertex using a deque-based BFS and the visiting order of a recursive DFS. Both functions keep a visited record so no vertex is processed twice.

graph_traversal.py

from collections import deque

graph = {
    "A": ["B", "C"],
    "B": ["A", "D"],
    "C": ["A", "D", "E"],
    "D": ["B", "C", "F"],
    "E": ["C", "F"],
    "F": ["D", "E"],
}


def bfs(start):
    """Shortest number of edges from start to every reachable vertex."""
    dist = {start: 0}
    queue = deque([start])
    while queue:
        node = queue.popleft()
        for nxt in graph[node]:
            if nxt not in dist:
                dist[nxt] = dist[node] + 1
                queue.append(nxt)
    return dist


def dfs(start):
    """Vertices in depth-first visiting order."""
    order, seen = [], set()

    def visit(node):
        seen.add(node)
        order.append(node)
        for nxt in graph[node]:
            if nxt not in seen:
                visit(nxt)

    visit(start)
    return order


print(bfs("A"))  # {'A': 0, 'B': 1, 'C': 1, 'D': 2, 'E': 2, 'F': 3}
print(dfs("A"))  # ['A', 'B', 'D', 'C', 'E', 'F']
python graph_traversal.py

Step-by-step guide

Six chapters that take you from installation to the core ideas of Graph traversal.

  1. Graph Traversal Concepts
  2. How It Works
  3. Implementation
  4. Complexity
  5. Practice Problems
  6. Real-World Use

Official docs and resources

  • Officialgraphlib — Functionality to operate with graph-like structures
  • LearnBreadth-first search (cp-algorithms)
  • LearnDepth First Search (cp-algorithms)
  • LearnGraph Traversal (DFS/BFS) — VisuAlgo
  • LearnMIT 6.006 Introduction to Algorithms (Spring 2020)
  • ReferenceBreadth-first search
  • ReferenceDepth-first search
  • ReferenceTopological sorting

Discussions

Start a discussion

Ask questions, share experience and trade opinions about Graph traversal.

No discussions yet. Start the first one.

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.