The order of the methods is not important here. This tells you how well the algorithms scale when the problem gets bigger and bigger. You cannot do any exact calculations if you only know O(n) == its complexity becomes linear in size of the problem. This will not give you any numbers.
This may mean that an algorithm with O(n) complexity is faster than an O(logn) algorithm for some n. Since O (log (n)) scales better when it gets bigger, we know for sure that there is n (problem size), where an algorithm with complexity O (logn) is faster. We just donβt know when (for what n ).
In plain English:
If you want to know how many searches, you need exact equations to solve, you need exact numbers. How many comparisons are required to search in sequential order? (Remember that n is given, so you can specify a number.) How many comparisons (in the worst case!) Are required for a binary search? Before you can perform a binary search, you will have to sort. Let the number of comparisons needed to sort the cost of the binary search be added. Now compare two numbers, which is less?
Binary searches are fast, but sorting is slow. Sequential searches are slower than binary searches, but faster than sorting. However, sorting should only be done once, no matter how many times you search. So, when does one heavy variety outweigh the need to perform a slow (sequential) search each time?
Good luck
source share