[Algorithm] Tree Traversal (Array/C++)

Changjin
Feb 2, 2021

Problem Link: https://binarysearch.com/problems/Tree-Traversal

Hello! Today we’ll be looking at a tree traversal problem. This can be solved quite simply once you know how to traverse to the right child, left child, and “parent”. Traversing to the right and left child is trivial but how can we jump to the parent? It can be solved using the hash map. First, we traverse from the root to the leaf nodes and save each node’s parent into the hash map. Then, perform the particular instructions given in the question.

Implementation

Time Complexity: O(n)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Changjin
Changjin

No responses yet

Write a response