DFS is an algorithm for traversing tree and graph data structures. It starts at a node, marks it as visited, and adds its unvisited neighbors to a stack. It then pops the top node from the stack and repeats this process, popping elements off the stack until none remain or are reachable, marking all visited nodes along the way. The example shows DFS traversing a graph from node A to fully explore it in depth-first order.