Data Structures & Algorithms In Go by Hemant Jain

Data Structures & Algorithms In Go by Hemant Jain

Author:Hemant Jain [Jain, Hemant]
Language: eng
Format: azw3, pdf
Publisher: UNKNOWN
Published: 2017-09-20T04:00:00+00:00


Complexity Analysis: Time Complexity: O(n), Space Complexity: O(n)

Nth Post Order

Solution: We want to print the node that will be at the nth index when we print the tree in post order traversal. Therefore, we keep a counter to keep track of the index, but at this time, we will increment the counter after left child and right child traversal. When the counter is equal to index, then we print the value and return the nth post-order index node.

Example 10.8

func (t *Tree) NthPostOrder(index int) {

var counter int

nthPostOrder(t.root, index, &counter)

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.