As I read from sources,I learnt that worst case complexity of Quad tree is O(N) when the 2D matrix has only one dimension.I am not able to understand the reason for this. For eg. When matrix is just 1xm,we'll keep dividing it into two halves and will reach unit cell in log(m) stops.So complexity should be log(m) THANKS
-
1You don't say which operation on the quad tree it is that is supposed to have the complexity *O(N)*. Only algorithms have time complexity classes, the tree itself can't have one. It would be a good idea to edit your question to make it clear what operation it is that you are asking about. – Lii Jun 05 '16 at 14:06
-
Complexity of what algorithm?? – Dr.Haimovitz Jun 05 '16 at 14:07
2 Answers
There are several ways of building a quad tree. If you take a matrix of pixels, or whatever units and make a quadtree out of it, then indeed it's height will be log(n).
However, if you use it to store points (kind of like a BST) that you add one after the other, then you'll hit the worst-case scenario if all of your points are sorted according to one components. In this case, height of the tree will be n.
An example of such a case is the following:
- Start with an empty quad tree
- Insert (0,0)
- Insert (1,1)
- Insert (2,2)
- Insert (3,3)
- ...
- Insert (n-1,n-1)
Each time you insert a node, it goes into the upper right corner of the previously inserted node, so each node has exactly one child. What you get at the end is just a weird linked list of length n.
So, it all depends of how you build your quadtree, and there is not a unique scheme to do that. That's why the worst-case complexity for operations like insert or search O(n).

- 11,380
- 1
- 17
- 28
In the worst case you have to search down to the lowest level of the
tree. Consider example when all elements except one in large quadrant/region of level 1, and you need to access the lowest level for at least one element. I need to see your slides / book, but something similar to {{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,63}}
should work.

- 31
- 2