Earlier quoted context omitted.
Depends. Sometimes the key isn't easily hash or comparable. For example, I know of a few case where the keys looks something like "if (a > b and c Now, that doesn't mean you can't hash a, b, c, and d. It just means that the logic around doing the lookups is nontrivial. When you are talking about < 100 elements, sometimes the consideration is "Welp, this is < 100, so lets just n^2 it".
> where the keys looks something like "if (a > b and c Confused, what do you mean when you say the key is an "if" statement?
O(n^2), again, now in Windows Management Instrumentation
121–130 of 232 posts
Re: O(n^2), again, now in Windows Management Instrumentation
#122Ah, this brings back the memory of my O(n^2) fiasco. I wrote a low level file system storage driver in the past. In the caching layer, there's a need to sort by LRU time for cache eviction. It's a minor thing not run often and I wanted to move quickly. Also since it's low level kernel mode code, I wanted the code to be simple and correct. The number of cache entries was not big. Bubble sort was adequate for small N,…
Quadratic, not exponential! :)
Re: O(n^2), again, now in Windows Management Instrumentation
#123Earlier quoted context omitted.
2^2^9 is 1.340781e+154
In this format, exponents are evaluated left to right, so this is 4^9 which is 262144 and is reasonable.
If you write a tower of 2^2^9 on a whiteboard and ask 1000 mathematicians and computer scientists to evaluate it, I'm sure 999 or 1000 of them would evaluate it as 2^(2^9).
[0] https://en.wikipedia.org/wiki/Order_of_operations#Serial_exp...
Re: O(n^2), again, now in Windows Management Instrumentation
#124Ah, this brings back the memory of my O(n^2) fiasco. I wrote a low level file system storage driver in the past. In the caching layer, there's a need to sort by LRU time for cache eviction. It's a minor thing not run often and I wanted to move quickly. Also since it's low level kernel mode code, I wanted the code to be simple and correct. The number of cache entries was not big. Bubble sort was adequate for small N,…
n^2 is polynomial, not exponential. If it was truly exponential (which a sort should never be unless you've decided to solve an arbitrary 3-SAT problem while sorting a list), then it would've blown up in your face much sooner.
Re: O(n^2), again, now in Windows Management Instrumentation
#125Earlier quoted context omitted.
I often see O(n^2) algorithms that can be reduced to O(2n) at the very least. One of the best things I gained from school was the red flag that fires off in my mind any time I see a loop nested in a loop.
you shouldn't call it O(2n), as there is already a constant inside of O(n), because it becomes 0 <= f(x) <= c*2n given a random f(x)
In reality, O(n) and O(2n) can be quite different for small n. As can O(n)+k0 and O(2n)+k1. Or worse, O(n^2)+k2 where sufficiently large k0 and k1 make the quadratic system better because it's k2 constant is so much smaller. Setup time matters.
Nowadays, you rarely have enough elements that the asymptotic behavior is the defining performance characteristic.
Re: O(n^2), again, now in Windows Management Instrumentation
#126Ah, this brings back the memory of my O(n^2) fiasco. I wrote a low level file system storage driver in the past. In the caching layer, there's a need to sort by LRU time for cache eviction. It's a minor thing not run often and I wanted to move quickly. Also since it's low level kernel mode code, I wanted the code to be simple and correct. The number of cache entries was not big. Bubble sort was adequate for small N,…
Quadratic, not exponential! :)
Re: O(n^2), again, now in Windows Management Instrumentation
#127Earlier quoted context omitted.
Quadratic, not exponential! :)
Would it be correct to say it's a quadratic complexity causing the run time to grow exponentially? Or is the word exponential still wrong here. My Mathematics terminology is rather.. dusty.
Re: O(n^2), again, now in Windows Management Instrumentation
#128Earlier quoted context omitted.
n^2 is polynomial, not exponential. If it was truly exponential (which a sort should never be unless you've decided to solve an arbitrary 3-SAT problem while sorting a list), then it would've blown up in your face much sooner.
What does exponential look like then?
Re: O(n^2), again, now in Windows Management Instrumentation
#129Earlier quoted context omitted.
Quadratic, not exponential! :)
Would it be correct to say it's a quadratic complexity causing the run time to grow exponentially? Or is the word exponential still wrong here. My Mathematics terminology is rather.. dusty.
- Quadratic = x^2, e.g. 0,1,4,9,16,25,36,49,64,81
- Exponential = n^x, for example 2^x, e.g. 1,2,4,8,16,32,64,128,256
Already very bad for small x even if n=2, but for n higher than 2 you can imagine you will run out of time very, very quickly ;-P
Re: O(n^2), again, now in Windows Management Instrumentation
#130Earlier quoted context omitted.
> where the keys looks something like "if (a > b and c Confused, what do you mean when you say the key is an "if" statement?
He probably meant, the lookup in the list is a conditional lookup based on a logic, instead of a simple key string.