#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1004
Task: Write a Python function that implements BFS and DFS on a simple adjacency list graph
Generated: 2026-02-12T16:42:36.878904
"""

# your code here
from collections import deque

def bfs(graph, start):
    visited = set()
    queue = deque([start])
    visited.add(start)
    result = []

    while queue:
        vertex = queue.popleft()
        result.append(vertex)
        for neighbor in graph[vertex]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append(neighbor)
    return result

def dfs(graph, start):
    visited = set()
    stack = [start]
    visited.add(start)
    result = []

    while stack:
        vertex = stack.pop()
        result.append(vertex)
        for neighbor in reversed(graph[vertex]):  # reversed for consistent order
            if neighbor not in visited:
                visited.add(neighbor)
                stack.append(neighbor)
    return result

if __name__ == '__main__':
    # Example graph represented as an adjacency list
    graph = {
        'A': ['B', 'C'],
        'B': ['A', 'D', 'E'],
        'C': ['A', 'F'],
        'D': ['B'],
        'E': ['B', 'F'],
        'F': ['C', 'E']
    }

    print("BFS traversal:")
    print(bfs(graph, 'A'))

    print("DFS traversal:")
    print(dfs(graph, 'A'))