41 cout <<
"=== K-Connected Graphs: Educational Examples ===\n\n";
47 cout <<
"--- Example 1: 1-Connected Graph (Has Bridges) ---\n\n";
52 cout <<
"SCENARIO: Simple network with weak link\n";
53 cout <<
"=======================================\n\n";
61 cout <<
"Network topology:\n";
62 cout <<
" Cluster 1: A --- B\n";
64 cout <<
" BRIDGE (single connection)\n";
66 cout <<
" Cluster 2: C --- D\n\n";
79 cout <<
"CONNECTIVITY ANALYSIS:\n";
80 cout <<
" * Edge connectivity: 1\n";
81 cout <<
" * Meaning: Removing 1 edge (the bridge) disconnects graph\n";
82 cout <<
" * Risk: Single point of failure!\n\n";
84 cout <<
"WHAT HAPPENS IF BRIDGE FAILS?\n";
85 cout <<
" Cluster 1 (A,B) is isolated from Cluster 2 (C,D)\n";
86 cout <<
" Network splits into two components\n";
87 cout <<
" No redundancy - catastrophic failure!\n\n";
89 cout <<
"REAL-WORLD: Internet backbone with single link between regions\n";
90 cout <<
" One cable cut = complete regional isolation\n\n";
97 cout <<
"--- Example 2: 2-Connected Graph (No Bridges) ---\n\n";
102 cout <<
"SCENARIO: Improved network with redundancy\n";
103 cout <<
"==========================================\n\n";
105 auto a =
network.insert_node(
"A");
106 auto b =
network.insert_node(
"B");
107 auto c =
network.insert_node(
"C");
108 auto d =
network.insert_node(
"D");
110 cout <<
"Network topology (cycle with diameter):\n";
111 cout <<
" A --- B\n";
113 cout <<
" | \\ | (diagonal A-C adds redundancy)\n";
114 cout <<
" D --- C\n\n";
132 cout <<
"CONNECTIVITY ANALYSIS:\n";
133 cout <<
" * Edge connectivity: 2\n";
134 cout <<
" * Meaning: Need to remove 2 edges to disconnect\n";
135 cout <<
" * Benefit: Can survive any single edge failure!\n\n";
137 cout <<
"FAILURE SCENARIOS:\n";
138 cout <<
" 1. Edge A-B fails:\n";
139 cout <<
" Alternative path: A → D → C → B\n";
140 cout <<
" Or: A → C → B\n";
141 cout <<
" Network stays connected ✓\n\n";
143 cout <<
" 2. Edge B-C fails:\n";
144 cout <<
" Alternative: B → A → C (via diagonal)\n";
145 cout <<
" Or: B → A → D → C\n";
146 cout <<
" Network stays connected ✓\n\n";
148 cout <<
"KEY INSIGHT: 2-connectivity = no single point of failure\n";
149 cout <<
" Every node reachable via multiple paths\n\n";
156 cout <<
"--- Example 3: Connectivity Level Comparison ---\n\n";
158 cout <<
"CONNECTIVITY LEVELS:\n";
159 cout <<
"===================\n\n";
161 cout <<
"k=0 (DISCONNECTED):\n";
162 cout <<
" A B C D\n";
163 cout <<
" Completely separate components\n";
164 cout <<
" Fault tolerance: None\n";
165 cout <<
" Use case: Independent subsystems\n\n";
167 cout <<
"k=1 (TREE/BRIDGE):\n";
168 cout <<
" A---B C---D\n";
171 cout <<
" Minimal connectivity\n";
172 cout <<
" Fault tolerance: Very low (any edge failure = disconnect)\n";
173 cout <<
" Use case: Hierarchical networks, cost-critical designs\n\n";
175 cout <<
"k=2 (CYCLE):\n";
179 cout <<
" Survives 1 edge failure\n";
180 cout <<
" Fault tolerance: Good (backup paths exist)\n";
181 cout <<
" Use case: Most practical networks\n\n";
183 cout <<
"k=3 (HIGHLY CONNECTED):\n";
186 cout <<
" |X X| (many cross-connections)\n";
189 cout <<
" Survives 2 edge failures\n";
190 cout <<
" Fault tolerance: Excellent\n";
191 cout <<
" Use case: Critical infrastructure, data centers\n\n";
193 cout <<
"TRADE-OFF:\n";
194 cout <<
" Higher k → More reliable BUT More expensive\n";
195 cout <<
" More edges → Higher cost (cables, maintenance)\n";
196 cout <<
" Design choice depends on criticality vs budget\n\n";
203 cout <<
"--- Example 4: Computing Edge Connectivity ---\n\n";
208 cout <<
"ALGORITHM: Uses maximum flow\n";
209 cout <<
"============================\n\n";
224 cout <<
"Graph: Square with diagonal\n";
228 cout <<
" 4---3\n\n";
230 cout <<
"COMPUTATION STEPS:\n";
231 cout <<
"1. Pick a source node (say, node 1)\n";
232 cout <<
"2. For each other node as sink:\n";
233 cout <<
" a. Build unit-capacity network\n";
234 cout <<
" b. Compute max-flow from source to sink\n";
235 cout <<
" c. Max-flow = number of edge-disjoint paths\n";
236 cout <<
"3. Minimum over all sinks = edge connectivity\n\n";
238 cout <<
"EXAMPLE CALCULATION:\n";
239 cout <<
" Node 1 to Node 2: max-flow = 2 (direct + via 4 or 3)\n";
240 cout <<
" Node 1 to Node 3: max-flow = 2 (direct + via 2 or 4)\n";
241 cout <<
" Node 1 to Node 4: max-flow = 2 (direct + via 2-3)\n";
242 cout <<
" Minimum = 2\n";
243 cout <<
" Edge connectivity = 2 ✓\n\n";
245 cout <<
"COMPLEXITY:\n";
246 cout <<
" * Need O(V) max-flow computations\n";
247 cout <<
" * Each max-flow: O(V * E^2) with Edmonds-Karp\n";
248 cout <<
" * Total: O(V^2 * E^2)\n";
249 cout <<
" * Practical for graphs with thousands of nodes\n\n";
256 cout <<
"--- Example 5: Designing Reliable Networks ---\n\n";
258 cout <<
"CASE STUDY: Data Center Network\n";
259 cout <<
"===============================\n\n";
261 cout <<
"REQUIREMENTS:\n";
262 cout <<
" * 100 servers must stay connected\n";
263 cout <<
" * Network must survive any 2 simultaneous failures\n";
264 cout <<
" * Minimize number of switches (cost)\n\n";
266 cout <<
"SOLUTION: 3-Connected Topology\n";
267 cout <<
" * Each server connects to 3 switches\n";
268 cout <<
" * Switches form highly connected mesh\n";
269 cout <<
" * Any 2 links can fail, connectivity preserved\n\n";
271 cout <<
"DESIGN CHOICES:\n\n";
273 cout <<
"Option A: Tree (k=1)\n";
274 cout <<
" Pros: Minimal cost (n-1 edges)\n";
275 cout <<
" Cons: No fault tolerance\n";
276 cout <<
" Decision: ✗ Too risky for data center\n\n";
278 cout <<
"Option B: Ring (k=2)\n";
279 cout <<
" Pros: Moderate cost, survives 1 failure\n";
280 cout <<
" Cons: Still vulnerable to 2 failures\n";
281 cout <<
" Decision: ✗ Insufficient for requirements\n\n";
283 cout <<
"Option C: 3-Connected Mesh (k=3)\n";
284 cout <<
" Pros: Survives 2 failures (meets requirement!)\n";
285 cout <<
" Cons: Higher cost (more cables)\n";
286 cout <<
" Decision: ✓ Best fit for critical infrastructure\n\n";
288 cout <<
"COST-BENEFIT ANALYSIS:\n";
289 cout <<
" Extra cost: ~50% more cables than ring\n";
290 cout <<
" Benefit: Can survive 2 simultaneous failures\n";
291 cout <<
" ROI: Downtime costs far exceed cable costs\n";
292 cout <<
" Conclusion: Worth the investment\n\n";
295 cout <<
"=== SUMMARY: K-Connected Graphs ===\n";
296 cout <<
"\n1. DEFINITION:\n";
297 cout <<
" k-connected: Removing any k-1 vertices keeps graph connected\n";
298 cout <<
" Edge connectivity: Min edges to remove to disconnect\n";
299 cout <<
" Higher k = more robust network\n";
300 cout <<
"\n2. CONNECTIVITY LEVELS:\n";
301 cout <<
" k=1: Tree-like, has bridges (weak)\n";
302 cout <<
" k=2: No bridges, survives 1 failure (good)\n";
303 cout <<
" k=3+: Highly redundant, very robust (excellent)\n";
304 cout <<
"\n3. HOW TO COMPUTE:\n";
305 cout <<
" Use maximum flow algorithm\n";
306 cout <<
" Build unit-capacity network\n";
307 cout <<
" Compute min-cut = edge connectivity\n";
308 cout <<
" Time: O(V^2 * E^2)\n";
309 cout <<
"\n4. DESIGN PRINCIPLES:\n";
310 cout <<
" * Critical systems: k ≥ 3 (data centers, hospitals)\n";
311 cout <<
" * Important systems: k = 2 (corporate networks)\n";
312 cout <<
" * Non-critical: k = 1 acceptable (home networks)\n";
313 cout <<
" * Always consider cost vs reliability trade-off\n";
314 cout <<
"\n5. REAL-WORLD APPLICATIONS:\n";
315 cout <<
" ✓ Internet backbone design\n";
316 cout <<
" ✓ Power grid planning\n";
317 cout <<
" ✓ Transportation networks\n";
318 cout <<
" ✓ Data center topologies\n";
319 cout <<
" ✓ Telecommunications infrastructure\n";
320 cout <<
"\n6. FAILURE ANALYSIS:\n";
321 cout <<
" k=1: Any edge failure → disconnect\n";
322 cout <<
" k=2: Survives 1 edge failure\n";
323 cout <<
" k=3: Survives 2 edge failures\n";
324 cout <<
" General: Survives k-1 failures\n";
325 cout <<
"\n7. COST CONSIDERATIONS:\n";
326 cout <<
" Tree (k=1): n-1 edges (minimum)\n";
327 cout <<
" Cycle (k=2): n edges (+1)\n";
328 cout <<
" Complete (k=n-1): n*(n-1)/2 edges (maximum)\n";
329 cout <<
" Practical: k=2 or k=3 for most applications\n";
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.