How can worst case complexity of quad tree O(N)?

穿精又带淫゛_ 提交于 2019-12-08 08:10:39

问题


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


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/37642688/how-can-worst-case-complexity-of-quad-tree-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!