3 ms·
I struggle with this sometimes, too. There are some examples that are very easy, but others that are very difficult. For example, finding a word in a dictionar
by Jemaclus 5y ago
I struggle with this sometimes, too. There are some examples that are very easy, but others that are very difficult.
For example, finding a word in a dictionary. One algorithm is to start at the beginning and read all the way through until you find it. Worst case scenario, you read all N records, thus it's O(N). A binary search would start 1/2 way through, then repeat with either half, depending on which branch you take, and you wind up with a worst case scenario of O(log N). Nested for loops often wind up as O(n^2).
Beyond that... I have a hard time being any more detailed than the ones I just mentioned.