I am trying to solve an exercise where you are given a perfect ternary tree in which each node contains an integer. We want to calculate how many internal nodes meet these specifications:
- The number of the node is larger than all its children
- It's largest child is the middle one
For example in the following tree there are only 3 nodes who meet these specifications
Design and analyze a divide and conquer algorithm which calculates the number of nodes who meet the specifications. This algorithm should be of O(n), where n is the number of leaves and n is a power of 3. Don't take into consideration the data structure of the tree, just explain a algorithm
So i tried designing this algorithm:
I am new to algorithm design and i do not know of what time complexity is what i did or even if it is a divide and conquer algorithm. Please if you know how to help me computing the time complexity of this or checking if it actually is a divide and conquer solution please tell me. Also if you have an idea that is better than mine please help out. Thanks