Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
87 views
in Information Technology by (178k points)
What is the time complexity of Morris Traversal?

Please log in or register to answer this question.

1 Answer

0 votes
by (178k points)

The time complexity of Morris Traversal is O(n), where n is the number of nodes in the binary tree. Morris Traversal achieves linear time complexity, making it an efficient in-place algorithm for inorder tree traversal.

Here's why Morris Traversal has a time complexity of O(n):

  1. Traversal Operation per Edge:

    • Each edge in the binary tree is traversed exactly twice—once to set the threaded link (to establish the connection to the inorder successor or predecessor) and once to reset the threaded link.
  2. Total Number of Operations:

    • The total number of operations for all edges in the tree is proportional to the number of nodes (n). In the worst case, every edge is traversed twice.
  3. Constant Factor:

    • The algorithm involves a constant amount of work per edge traversal, as the operations for establishing and resetting the threaded links are constant-time operations.

Therefore, the overall time complexity is O(n), making Morris Traversal particularly useful when there are constraints on using extra space (like a stack) for tree traversal. It achieves an efficient in-order traversal without the need for additional data structures, making it a space-efficient and linear-time solution.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...