Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
Traversal algorithms are methods used to visit and process all elements in a data structure, such as arrays, linked lists, or trees. They allow you to access each element individually and perform operations on them.
Related terms
Depth-First Search (DFS): DFS is a traversal algorithm that explores as far as possible along each branch before backtracking. It uses a stack to keep track of visited nodes.
Breadth-First Search (BFS): BFS is a traversal algorithm that explores all the vertices of a graph in breadth-first order, meaning it visits all neighbors before moving on to their neighbors. It uses a queue to maintain the order of exploration.
In-order Traversal: In-order traversal is commonly used for binary trees and visits nodes in ascending order when applied to binary search trees. It follows the pattern left subtree - root - right subtree.