Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Linux Tipps & HardeningVAXEE NP-01 Ergo Wireless (8K) mouse thoughts(24.09.2026 um 12:38 Uhr)
Linux Tipps & HardeningQualcomm Announces Snapdragon X2 Series Processors Will Support Linux(24.09.2026 um 12:04 Uhr)
Linux Tipps & HardeningBlack Friday 2026 Phone Deals: Best iPhone, Samsung and More(24.09.2026 um 12:39 Uhr)
Linux Tipps & HardeningDont Trust Qualcomm for X2 Elite Linux Support! Liars!(24.09.2026 um 12:59 Uhr)
KI & AI VideosJulian Goldie SEO: LIVE: Building Agent OS with Claude!(24.09.2026 um 12:16 Uhr)
Linux Tipps & HardeningVAXEE NP-01 Ergo Wireless (8K) mouse thoughts(24.09.2026 um 12:38 Uhr)
Linux Tipps & HardeningQualcomm Announces Snapdragon X2 Series Processors Will Support Linux(24.09.2026 um 12:04 Uhr)
Linux Tipps & HardeningBlack Friday 2026 Phone Deals: Best iPhone, Samsung and More(24.09.2026 um 12:39 Uhr)
Linux Tipps & HardeningDont Trust Qualcomm for X2 Elite Linux Support! Liars!(24.09.2026 um 12:59 Uhr)
KI & AI VideosJulian Goldie SEO: LIVE: Building Agent OS with Claude!(24.09.2026 um 12:16 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Learn Topological Sort by Making a Build Graph Explain Its Cycle

A build graph contains these edges: parse -> typecheck -> bundle -> parse There is no valid first task. A topological sort should not return a partial list and quietly stop; it should explain why the graph cannot be…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

A build graph contains these edges:




parse -> typecheck -> bundle -> parse






There is no valid first task. A topological sort should not return a partial list and quietly stop; it should explain why the graph cannot be ordered.



This project teaches two connected ideas:




  1. Kahn's algorithm produces an order for a directed acyclic graph (DAG).

  2. A separate depth-first search can turn “some cycle exists” into a concrete cycle a learner can inspect.



Prerequisites: Python 3.11+ and basic familiarity with dictionaries, sets, and queues. The code uses only the standard library.






Define the graph contract



We represent each task with the tasks it depends on:




graph = {
"bundle": {"typecheck"},
"typecheck": {"parse"},
"parse": set(),
}






An edge parse -> typecheck means parse must appear first. A dependency mentioned only inside a set is still a node, so normalization must add it.






Order the acyclic case



Kahn's algorithm tracks each node's in-degree: the number of prerequisites not yet removed.




from collections import deque


def normalize(graph):
nodes = set(graph)
for dependencies in graph.values():
nodes.update(dependencies)
return {node: set(graph.get(node, set())) for node in nodes}


def topological_order(graph):
dependencies = normalize(graph)
dependents = {node: set() for node in dependencies}

for node, prerequisites in dependencies.items():
for prerequisite in prerequisites:
dependents[prerequisite].add(node)

ready = deque(sorted(
node for node, prerequisites in dependencies.items()
if not prerequisites
))
order = []

while ready:
node = ready.popleft()
order.append(node)

for dependent in sorted(dependents[node]):
dependencies[dependent].remove(node)
if not dependencies[dependent]:
ready.append(dependent)

remaining = {node for node, deps in dependencies.items() if deps}
if remaining:
return None, remaining
return order, set()






Try it:




graph = {
"bundle": {"typecheck"},
"typecheck": {"parse"},
"parse": set(),
"test": {"typecheck"},
}

print(topological_order(graph))






Expected output (the exact order of equally ready tasks depends on queue policy):




(['parse', 'typecheck', 'bundle', 'test'], set())






Sorting ready names makes this example deterministic. Real schedulers may instead prioritize cost, critical path, or resource availability.






Why a partial result is not enough



Now introduce a cycle:




cyclic = {
"parse": {"bundle"},
"typecheck": {"parse"},
"bundle": {"typecheck"},
}

print(topological_order(cyclic))






Expected result:




(None, {'parse', 'typecheck', 'bundle'})






Kahn's algorithm proves ordering failed, but remaining can include nodes merely blocked by a cycle. It does not necessarily show cycle edges. We need a second pass.






Extract one concrete cycle



Depth-first search assigns three states:





  • unseen: not visited;


  • active: on the current recursion path;


  • done: fully explored.



An edge to an active node is a back edge and therefore closes a cycle.




def find_cycle(graph, candidates=None):
graph = normalize(graph)
allowed = set(graph) if candidates is None else set(candidates)
state = {node: "unseen" for node in graph}
stack = []
position = {}

def visit(node):
state[node] = "active"
position[node] = len(stack)
stack.append(node)

for dependency in sorted(graph[node]):
if dependency not in allowed:
continue
if state[dependency] == "unseen":
cycle = visit(dependency)
if cycle:
return cycle
elif state[dependency] == "active":
start = position[dependency]
return stack[start:] + [dependency]

stack.pop()
position.pop(node)
state[node] = "done"
return None

for node in sorted(allowed):
if state[node] == "unseen":
cycle = visit(node)
if cycle:
return cycle
return None






Combine both stages:




def schedule(graph):
order, remaining = topological_order(graph)
if order is not None:
return {"order": order, "cycle": None}
return {"order": None, "cycle": find_cycle(graph, remaining)}

print(schedule(cyclic))






Expected structure:




{'order': None, 'cycle': ['bundle', 'typecheck', 'parse', 'bundle']}






The start node may vary, but the last item must equal the first, and every adjacent pair must be a real dependency edge.






Tests that verify meaning



Avoid testing only one exact printed cycle because several rotations can be correct.




def assert_valid_order(graph, order):
index = {node: i for i, node in enumerate(order)}
normalized = normalize(graph)
assert set(order) == set(normalized)
for node, dependencies in normalized.items():
for dependency in dependencies:
assert index[dependency] < index[node]


def assert_valid_cycle(graph, cycle):
normalized = normalize(graph)
assert cycle[0] == cycle[-1]
for node, dependency in zip(cycle, cycle[1:]):
assert dependency in normalized[node]


order, remaining = topological_order(graph)
assert remaining == set()
assert_valid_order(graph, order)

result = schedule(cyclic)
assert result["order"] is None
assert_valid_cycle(cyclic, result["cycle"])






Add three error-shaped fixtures:




# Self-cycle
assert_valid_cycle({"a": {"a"}}, schedule({"a": {"a"}})["cycle"])

# A cycle plus a node blocked by it
blocked = {"a": {"b"}, "b": {"a"}, "deploy": {"a"}}
assert_valid_cycle(blocked, schedule(blocked)["cycle"])

# A disconnected valid component plus a cycle
mixed = {"lint": set(), "a": {"b"}, "b": {"a"}}
assert_valid_cycle(mixed, schedule(mixed)["cycle"])









Complexity and limitations



Both passes are O(V + E) apart from sorting, which adds deterministic output at a cost. Recursive DFS can hit Python's recursion limit on very deep graphs; an iterative stack is safer for untrusted or huge input.



This scheduler also assumes dependencies are static and tasks consume no limited resources. A production build system must consider caching, parallelism, task failures, and changing inputs. Topological order answers only one question: which precedence constraints are mathematically possible?






What you should understand



Kahn's algorithm and DFS do different jobs. Kahn's algorithm constructs an order and detects that some dependency cannot be removed. DFS explains a specific contradiction in the graph. Combining them produces both a useful success result and a useful failure result.



As an extension, change find_cycle() to return every strongly connected component with more than one node. That leads naturally to Tarjan's or Kosaraju's algorithm—and to better diagnostics for real build graphs.

CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Learn Topological Sort by Making a Build Graph Explain Its Cycle
id: 288fbd1d-ecab-4122-a0db-7aa521f58cc8
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Learn Topological Sort by Maki" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Learn Topological Sort by Making a Build.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Learn Topological Sort by Making a Build Graph Explain Its Cycle

Thematisch verwandte Begriffe: Learn, Topological, Sort, Making · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97152 | Nanomsg versions 0.5-beta through 1.x before 1.2.3 has a remotely exploi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick