I am currently watching the FreeCodeCamp Algorithms and Data Structures Tutorial. In the explanation for exponential time complexity, they explain that using a brute force attack on a combination lock would create O(x^n) time complexity. I am confused as this attack sounds very similar to a linear search of the passcode, going one by one until you find the right combination.
The confusion comes when you find that while brute force has a time complexity of O(x^n), linear search only has a time complexity of O(n). This therefore means that, depending on what you call the algorithm, the same instructions can have differing time complexities, which makes no sense.
Can someone explain whether FreeCodeCamp have made an error in the course or I am mistaken?
Thanks :)
O(n)
terminology. Bubblesort is O(n) for a clever-enough definition ofn
. It's a few more characters, but much more clear to say that brute forcing a combination lock isO(alphabet.size^digit_count)
. Then these sorts of questions just disappear $\endgroup$std::partial_sort
is defined like this: "Approximately (last-first)log(middle-first) applications ofcmp
." Where last, first, middle, and cmp are the parameters of the function. No Oh, Omega, Omicron, or Theta in sight. Also, no N. $\endgroup$std::sort
does use Big-Oh, and does use N, but at least, it explicitly and clearly defines what, exactly, N is: "O(N·log(N)) comparisons, where N isstd::distance(first, last)
." They also clearly define what operations they are counting, namely comparisons. $\endgroup$