Fiveable
Fiveable

Traversal

Definition

Traversal refers to the process of visiting and accessing each element in a data structure, such as an array or a tree, in a specific order.

Analogy

Imagine you have a bookshelf with many books. To find a specific book, you need to traverse the entire shelf, checking each book until you find the one you're looking for.

Related terms

Preorder traversal: A type of traversal where the root node is visited first, followed by its left subtree and then its right subtree.

Inorder traversal: A type of traversal where the left subtree is visited first, followed by the root node and then the right subtree.

Postorder traversal: A type of traversal where the left subtree is visited first, followed by the right subtree and then finally the root node.



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.