I'm looking to calulate the time complexity of the following algorithm.
I have an AVL tree and a pair of two numbers (x,y) such that x<y.
The algorithm's purpose is to print all numbers in the tree between x and y.
x and y are definitly not in the tree.
My goal is to make an algorithm whose runtime is O(logn + k) such that k is the number of nodes between x and y and n is the total number of nodes in the tree.
my algorithm is this:
A function that receives x and y, starts from the root of the tree and goes like this:
if the current node is between x and y - print it and recursively call the left node with (x,current node value) and the right node with (current node value,y).
if the current node is smaller than x - call the right node recursivley with (x,y)
if the current node is bigger than y - call the left node recursivley with (x,y) The function stops when it reaches a leaf(node who has no other nodes attached to it). Does my function meet the runtime requirement?