CARVIEW |
Select Language
HTTP/2 307
date: Sun, 12 Oct 2025 05:33:54 GMT
content-type: text/html
content-length: 46
location: https://how.dev/answers/what-is-tree-traversal
cf-ray: 98d4399deca6ccbb-BLR
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-robots-tag: all
x-nextjs-cache: MISS
x-cloud-trace-context: f78f076c1337fb41160a5324947bae0b
via: 1.1 google
alt-svc: h3=":443"; ma=86400
cf-cache-status: MISS
set-cookie: __cf_bm=Mvb3B6r22YS.NAb1HUQyedZ8PFku6mMeKHf1oGyLv7g-1760247234-1.0.1.1-wJEzD887W3zfareyuazXiE0bf31R4AU5ipVdbOCU_N1ToqYpyzWCyA9LWtLj55WwbczvE4uP_RCsWqG3..BlETljVKYiS4iqtUJwU11m_FM; path=/; expires=Sun, 12-Oct-25 06:03:54 GMT; domain=.educative.io; HttpOnly; Secure; SameSite=None
vary: Accept-Encoding
strict-transport-security: max-age=31536000; includeSubDomains; preload
server: cloudflare
HTTP/2 200
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-middleware-rewrite: /answers/howdev/what-is-tree-traversal
x-nextjs-cache: MISS
etag: W/"48rpubcgxv45mhy"
content-type: text/html; charset=utf-8
x-cloud-trace-context: d0edd8b0bb6723da1b6517d798a91e48
date: Sun, 12 Oct 2025 05:33:58 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache-status: miss
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
What is tree traversal? 



What is tree traversal?
A tree is a widely used data structure in the world of programming. This structure, like its name, has branches and subdivisions, where each element in the tree is called a node.
For a tree to be “traversed” means that every node within the tree has been visited.
Where most data structures can be traversed in one or two ways by virtue of being linear, trees have a hierarchical structure and hence they can be traversed in multiple ways. Before we understand what these types are, we need to be familiar with a few terms.
- root: The first node of the tree (generally portrayed as the top-most node).
- parent: Each node that has a branch leading out from it, is called the parent of the subsequent node(s).
- children: The node(s) that extend from the parent are called children; the left and the right child depending on the placement of the node.
Types of traversals
Depth First Traversals
- Inorder: First, you traverse the left child and its sub-tree, visit the root and then the right child and its sub-tree.
- Preorder: Visit the root first, then traverse the left sub-tree, and then the right sub-tree.
- Postorder: Traverse the left sub-tree, then traverse the right sub-tree and then visit the root node.
Breadth First Traversals
- Levelorder: This traverses nodes by levels instead of sub-trees. First, visit the root node; then visit all children of the root node- left to right. Subsequently, go down levels till you reach the node that has no children- the leaf nodes.
Relevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved