Inorder Traversal

Binary Trees Theory/Traversals Easy
  • Fun Fact: The Inorder traversal of a binary tree is commonly used in software development to process and manage hierarchical data structures, such as the Document Object Model (DOM) in web development
  • The DOM represents a web page so programs can change the document structure, style, and content
  • By using Inorder traversal, developers can efficiently access and manipulate elements on the webpage in the exact order they appear in the HTML markup, allowing for specific and efficient modifications to web content

Given root of binary tree, return the Inorder traversal of the binary tree.

Examples:

Input : root = [1, 4, null, 4, 2]

Output : [4, 4, 2, 1]

Explanation :


Input : root = [1, null, 2, 3]

Output : [1, 3, 2]

Explanation :


Input : root = [5, 1, 2, 8, null, 4, 5, null, 6]

Constraints

  • 1 <= Number of Nodes <= 100
  • -100 Node.val <= 100

Hints

  • Since inorder traversal first visits the left subtree, we use a stack to store nodes while traversing left.
  • Push nodes onto the stack while moving left, process them, then move to their right child.

Company Tags

Broadcom ARM Seagate Technology Rockstar Games Freshworks Johnson & Johnson PayPal HashiCorp Medtronic Goldman Sachs Epic Games Flipkart Wayfair Snowflake Intel AMD Morgan Stanley Uber Airbnb Target Swiggy MongoDB Boston Consulting Group Reddit Bloomberg Google Microsoft Amazon Meta Apple Netflix Adobe