I have an assignment that wants me to write an ternary search algorithm and compute its time complexity afterwards. I was able to write an algorithm for it but I couldn\'t c
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
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).