Time Complexity of Ternary Search Algorithm

ぐ巨炮叔叔 提交于 2019-12-01 01:20:15

At each step, you are reducing the size of the searchable range by a constant factor (in this case 3). If you find your element after n steps, then the searchable range has size N = 3n. Inversely, the number of steps that you need until you find the element is the logarithm of the size of the collection. That is, the runtime is O(log N). A little further thought shows that you can also always construct situations where you need all those steps, so the worst-case runtime is actually Θ(log N).

It is Θ(log3(N)). To check how to calculate complexity just check http://en.wikipedia.org/wiki/Big_O_notation

To read more about ternary search, just check the wikipedia page also: http://en.wikipedia.org/wiki/Ternary_search

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