Big-O for Eight Year Olds?

Question: I'm asking more about what this means to my code.  I understand the concepts mathematically, I just have a hard time wrapping my head around what they mean conceptually.  For example, if one were to perform an O(1) operation on a data structure, I understand that the number of operations it has to perform won't grow because there are more items.  And an O(n) operation would mean that you would perform a set of operations on each element.  Could somebody fill in the blanks here?

Like what exactly would an O(n^2) operation do?
And what the heck does it mean if an operation is O(n log(n))?
And does somebody have to smoke crack to write an O(x!)?
Comment: This has been answered pretty well so I won't bother. I just wanted to say I love the title of your question! Using the concept that you don't really understand something until you can explain it to an 8yr old is a great way to phrase the question.
Comment: Wouldn't the title be better phrased as say, 'What is a simple explanation of Big-O?', etc.
Comment: @TMarshall It may be an interesting title, but that doesn't mean it's necessarily searchable.
Comment: @bradtgmurray: or rated PG...
Comment: *Does somebody have to smoke crack to write an O(x!)?* Legendary!
Comment: When I read this I thought you were talking about:
http://en.wikipedia.org/wiki/The_Big_O
Comment: @RobertSCiaccio Can you elaborate? :P
Comment: @muntoo: I don't think I want to go there :P
Comment: Nice cheat sheet here as well: http://bigocheatsheet.com
Comment: @Alex Late to the party: *Cast in the name of God, Ye not guilty.*
Comment: @XtremeBiker I'll ask doug stamper to look into it
Comment: Please consider letting your eight year olds play with toys and may be some computer games.
Comment: This question's title looks exactly like it was written by an 8-year-old. :)
Answer: One way of thinking about it is this:
O(N^2) means for every element, you're doing something with every other element, such as comparing them.  Bubble sort is an example of this.
O(N log N) means for every element, you're doing something that only needs to look at log N of the elements.  This is usually because you know something about the elements that let you make an efficient choice.  Most efficient sorts are an example of this, such as merge sort.
O(N!) means to do something for all possible permutations of the N elements.  Traveling salesman is an example of this, where there are N! ways to visit the nodes, and the brute force solution is to look at the total cost of every possible permutation to find the optimal one.
Comment: Good explanation, although it should be noted that it is what it says - "a way of thinking about it" rather than the literal truth. For instance, if for half the elements you do something with half the other elements, that's still O(n^2)
Comment: In nearly all cases, O(N log N) means you are either sorting the input, or storing it in such as way that you can read it back in sorted order.
Answer: The big thing that Big-O notation means to your code is how it will scale when you double the amount of "things" it operates on.  Here's a concrete example:

Big-O       |  computations for 10 things |  computations for 100 things
----------------------------------------------------------------------
O(1)        |   1                         |     1
O(log(n))   |   3                         |     7
O(n)        |  10                         |   100
O(n log(n)) |  30                         |   700
O(n^2)      | 100                         | 10000

So take quicksort which is O(n log(n)) vs bubble sort which is O(n^2).  When sorting 10 things, quicksort is 3 times faster than bubble sort.  But when sorting 100 things, it's 14 times faster!  Clearly picking the fastest algorithm is important then.  When you get to databases with million rows, it can mean the difference between your query executing in 0.2 seconds, versus taking hours.
Another thing to consider is that a bad algorithm is one thing that Moore's law cannot help.  For example, if you've got some scientific calculation that's O(n^3) and it can compute 100 things a day, doubling the processor speed only gets you 125 things in a day.  However, knock that calculation to O(n^2) and you're doing 1000 things a day.
clarification:
Actually, Big-O says nothing about comparative performance of different algorithms at the same specific size point, but rather about comparative performance of the same algorithm at different size points:
                 computations     computations       computations
Big-O       |   for 10 things |  for 100 things |  for 1000 things
----------------------------------------------------------------------
O(1)        |        1        |        1        |         1
O(log(n))   |        1        |        3        |         7
O(n)        |        1        |       10        |       100
O(n log(n)) |        1        |       33        |       664
O(n^2)      |        1        |      100        |     10000
Comment: While it is surely helpful, I do not think this is the best way to describe it, because this explanation gives rise to a very common misconception about Big-O. Some people erroneously tend to think that "_An O(1) algorithm is always better than an O(n) algorithm_". While that is most often the case, it is not always true. It is possible to, on one hand, have an O(1) function which operates on a set of N numbers, and takes roughly 1 second to execute regardless of N. On the other hand, an O(N) function doing the same thing in 1 ms for N = 1kk and 5 ms for N = 5kk and 100 ms for N = 100kk.
Answer: You might find it useful to visualize it:

Also, on  LogY/LogX scale the functions  n1/2, n, n2  all look like straight lines, while on LogY/X scale  2n, en, 10n  are straight lines and n! is linearithmic (looks like n log n).
Comment: for completeness, it'd be cool if two more graphs be added here: one on  **LogY/LogX** scale (so n^(1/2), n, n^2 are  [straight lines](http://en.wikipedia.org/wiki/Analysis_of_algorithms#Empirical_orders_of_growth)) and the other on **LogY/X** scale (so 2^n, e^n, 10^n are straight lines and n! is linearithmic (looks like nlogn)).
Comment: I went ahead and made a suggestive edit, hope it's cool by you. :)
Answer: This might be too mathematical, but here's my try. (I am a mathematician.)
If something is O(f(n)), then it's running time on n elements will be equal to A f(n) + B  (measured in, say, clock cycles or CPU operations). It's key to understanding that you also have these constants A and B, which arise from the specific implementation. B represents essentially the "constant overhead" of your operation, for example some preprocessing that you do that doesn't depend on the size of the collection. A represents the speed of your actual item-processing algorithm.
The key, though, is that you use big O notation to figure out how well something will scale. So those constants won't really matter: if you're trying to figure out how to scale from 10 to 10000 items, who cares about the constant overhead B? Similarly, other concerns (see below) will certainly outweigh the weight of the multiplicative constant A.
So the real deal is f(n). If f grows not at all with n, e.g. f(n) = 1, then you'll scale fantastically---your running time will always just be A + B. If f grows linearly with n, i.e. f(n) = n, your running time will scale pretty much as best as can be expected---if your users are waiting 10 ns for 10 elements, they'll wait 10000 ns for 10000 elements (ignoring the additive constant). But if it grows faster, like n2, then you're in trouble; things will start slowing down way too much when you get larger collections. f(n) = n log(n) is a good compromise, usually: your operation can't be so simple as to give linear scaling, but you've managed to cut things down such that it'll scale much better than f(n) = n2.
Practically, here are some good examples:

O(1): retrieving an element from an array. We know exactly where it is in memory, so we just go get it. It doesn't matter if the collection has 10 items or 10000; it's still at index (say) 3, so we just jump to location 3 in memory.
O(n): retrieving an element from a linked list. Here, A = 0.5, because on average you''ll have to go through 1/2 of the linked list before you find the element you're looking for.
O(n2): various "dumb" sorting algorithms. Because generally their strategy involves, for each element (n), you look at all the other elements (so times another n, giving n2), then position yourself in the right place.
O(n log(n)): various "smart" sorting algorithms. It turns out that you only need to look at, say, 10 elements in a 1010-element collection to intelligently sort yourself relative to everyone else in the collection. Because everyone else is also going to look at 10 elements, and the emergent behavior is orchestrated just right so that this is enough to produce a sorted list.
O(n!): an algorithm that "tries everything," since there are (proportional to) n! possible combinations of n elements that might solve a given problem. So it just loops through all such combinations, tries them, then stops whenever it succeeds.
Comment: Nit, `O(f(n))` means that it's less than or equal to `A f(n) + B`.
Answer: don.neufeld's answer is very good, but I'd probably explain it in two parts: first, there's a rough hierarchy of O()'s that most algorithms fall into. Then, you can look at each of those to come up with sketches of what typical algorithms of that time complexity do.
For practical purposes, the only O()'s that ever seem to matter are:

O(1) "constant time" - the time required is independent of the size of the input. As a rough category, I would include algorithms such as hash lookups and Union-Find here, even though neither of those are actually O(1).
O(log(n)) "logarithmic" - it gets slower as you get larger inputs, but once your input gets fairly large, it won't change enough to worry about. If your runtime is ok with reasonably-sized data, you can swamp it with as much additional data as you want and it'll still be ok.
O(n) "linear" - the more input, the longer it takes, in an even tradeoff. Three times the input size will take roughly three times as long.
O(n log(n)) "better than quadratic" - increasing the input size hurts, but it's still manageable. The algorithm is probably decent, it's just that the underlying problem is more difficult (decisions are less localized with respect to the input data) than those problems that can be solved in linear time. If your input sizes are getting up there, don't assume that you could necessarily handle twice the size without changing your architecture around (eg by moving things to overnight batch computations, or not doing things per-frame). It's ok if the input size increases a little bit, though; just watch out for multiples.
O(n^2) "quadratic" - it's really only going to work up to a certain size of your input, so pay attention to how big it could get. Also, your algorithm may suck -- think hard to see if there's an O(n log(n)) algorithm that would give you what you need. Once you're here, feel very grateful for the amazing hardware we've been gifted with. Not long ago, what you are trying to do would have been impossible for all practical purposes.
O(n^3) "cubic" - not qualitatively all that different from O(n^2). The same comments apply, only more so. There's a decent chance that a more clever algorithm could shave this time down to something smaller, eg O(n^2 log(n)) or O(n^2.8...), but then again, there's a good chance that it won't be worth the trouble. (You're already limited in your practical input size, so the constant factors that may be required for the more clever algorithms will probably swamp their advantages for practical cases. Also, thinking is slow; letting the computer chew on it may save you time overall.)
O(2^n) "exponential" - the problem is either fundamentally computationally hard or you're being an idiot. These problems have a recognizable flavor to them. Your input sizes are capped at a fairly specific hard limit. You'll know quickly whether you fit into that limit.

And that's it. There are many other possibilities that fit between these (or are greater than O(2^n)), but they don't often happen in practice and they're not qualitatively much different from one of these. Cubic algorithms are already a bit of a stretch; I only included them because I've run into them often enough to be worth mentioning (eg matrix multiplication).
What's actually happening for these classes of algorithms? Well, I think you had a good start, although there are many examples that wouldn't fit these characterizations. But for the above, I'd say it usually goes something like:

O(1) - you're only looking at most at a fixed-size chunk of your input data, and possibly none of it. Example: the maximum of a sorted list.

Or your input size is bounded. Example: addition of two numbers. (Note that addition of N numbers is linear time.)

O(log n) - each element of your input tells you enough to ignore a large fraction of the rest of the input. Example: when you look at an array element in binary search, its value tells you that you can ignore "half" of your array without looking at any of it. Or similarly, the element you look at gives you enough of a summary of a fraction of the remaining input that you won't need to look at it.

There's nothing special about halves, though -- if you can only ignore 10% of your input at each step, it's still logarithmic.

O(n) - you do some fixed amount of work per input element. (But see below.)
O(n log(n)) - there are a few variants.

You can divide the input into two piles (in no more than linear time), solve the problem independently on each pile, and then combine the two piles to form the final solution. The independence of the two piles is key. Example: classic recursive mergesort.
Each linear-time pass over the data gets you halfway to your solution. Example: quicksort if you think in terms of the maximum distance of each element to its final sorted position at each partitioning step (and yes, I know that it's actually O(n^2) because of degenerate pivot choices. But practically speaking, it falls into my O(n log(n)) category.)

O(n^2) - you have to look at every pair of input elements.

Or you don't, but you think you do, and you're using the wrong algorithm.

O(n^3) - um... I don't have a snappy characterization of these. It's probably one of:

You're multiplying matrices
You're looking at every pair of inputs but the operation you do requires looking at all of the inputs again
the entire graph structure of your input is relevant

O(2^n) - you need to consider every possible subset of your inputs.

None of these are rigorous. Especially not linear time algorithms (O(n)): I could come up with a number of examples where you have to look at all of the inputs, then half of them, then half of those, etc. Or the other way around -- you fold together pairs of inputs, then recurse on the output. These don't fit the description above, since you're not looking at each input once, but it still comes out in linear time. Still, 99.2% of the time, linear time means looking at each input once.
Comment: "O(2^n) "exponential" - the problem is either fundamentally computationally hard or you're being an idiot." I laughed. +1
Comment: and then there are factoring algorithms, somewhere between sqrt(n)=naive and log(n)=impossible
Comment: actually matrix multiplication is sub-n^3 (the regular way is n^3), see the Strassen algorithm (n^(log_2(7)))
Comment: O(sqrt(n)) - good one. That is indeed a missing meaningful level. I should add that. But re: matrix multiplication -- that's mostly what I was thinking about in my "cubic" bullet point (it's where the n^2.8... came from.) I still assert it isn't worth the extra overhead in most practical cases.
Answer: A lot of these are easy to demonstrate with something non-programming, like shuffling cards.
Sorting a deck of cards by going through the whole deck to find the ace of spades, then going through the whole deck to find the 2 of spades, and so on would be worst case n^2, if the deck was already sorted backwards. You looked at all 52 cards 52 times.
In general the really bad algorithms aren't necessarily intentional, they're commonly a misuse of something else, like calling a method that is linear inside some other method that repeats over the same set linearly.
Answer: I try to explain by giving simple code examples in C# and JavaScript.
C#
For List<int> numbers = new List<int> {1,2,3,4,5,6,7,12,543,7};
O(1) looks like
return numbers.First();

O(n) looks like
int result = 0;
foreach (int num in numbers)
{
  result += num;
}
return result;

O(n log(n)) looks like
int result = 0;
foreach (int num in numbers)
{
    int index = numbers.Count - 1;
    while (index > 1)
    {
        // yeah, stupid, but couldn't come up with something more useful :-(
        result += numbers[index];
        index /= 2;
    }
}
return result;

O(n2) looks like
int result = 0;
foreach (int outerNum in numbers)
{
    foreach (int innerNum in numbers)
    {
        result += outerNum * innerNum;
    }
}
return result;

O(n!) looks like, uhm, to tired to come up with anything simple.
But I hope you get the general point?

JavaScript
For const numbers = [ 1, 2, 3, 4, 5, 6, 7, 12, 543, 7 ];
O(1) looks like
numbers[0];

O(n) looks like
let result = 0;
for (num of numbers){
    result += num;
}

O(n log(n)) looks like
let result = 0;
for (num of numbers){

    let index = numbers.length - 1;
    while (index > 1){
        // yeah, stupid, but couldn't come up with something more useful :-(
        result += numbers[index];
        index = Math.floor(index/2)
    }
}

O(n2) looks like
let result = 0;
for (outerNum of numbers){
    for (innerNum of numbers){
        result += outerNum * innerNum;
    }
}

Comment: fibonacci sequence would be n! if it is calculated using naive calculation approach and if previous term is not stored.
Answer: Ok - there are some very good answers here but almost all of them seem to make the same mistake and it's one that is pervading common usage.
Informally, we write that f(n) = O( g(n) ) if, up to a scaling factor and for all n larger than some n0, g(n) is larger than f(n). That is, f(n) grows no quicker than, or is bounded from above by, g(n). This tells us nothing about how fast f(n) grows, save for the fact that it is guaranteed not to be any worse than g(n).
A concrete example: n = O( 2^n ). We all know that n grows much less quickly than 2^n, so that entitles us to say that it is bounded by above by the exponential function. There is a lot of room between n and 2^n, so it's not a very tight bound, but it's still a legitimate bound.
Why do we (computer scientists) use bounds rather than being exact? Because a) bounds are often easier to prove and b) it gives us a short-hand to express properties of algorithms. If I say that my new algorithm is O(n.log n) that means that in the worst case its run-time will be bounded from above by n.log n on n inputs, for large enough n (although see my comments below on when I might not mean worst-case).
If instead, we want to say that a function grows exactly as quickly as some other function, we use theta to make that point (I'll write T( f(n) ) to mean \Theta of f(n) in markdown). T( g(n) ) is short hand for being bounded from above and below by g(n), again, up to a scaling factor and asymptotically.
That is f(n) = T( g(n) ) <=> f(n) = O(g(n)) and g(n) = O(f(n)). In our example, we can see that n != T( 2^n ) because 2^n != O(n).
Why get concerned about this? Because in your question you write 'would someone have to smoke crack to write an O(x!)?' The answer is no - because basically everything you write will be bounded from above by the factorial function. The run time of quicksort is O(n!) - it's just not a tight bound.
There's also another dimension of subtlety here. Typically we are talking about the worst case input when we use O( g(n) ) notation, so that we are making a compound statement: in the worst case running time it will not be any worse than an algorithm that takes g(n) steps, again modulo scaling and for large enough n. But sometimes we want to talk about the running time of the average and even best cases.
Vanilla quicksort is, as ever, a good example. It's T( n^2 ) in the worst case (it will actually take at least n^2 steps, but not significantly more), but T(n.log n) in the average case, which is to say the expected number of steps is proportional to n.log n. In the best case it is also T(n.log n) - but you could improve that for, by example, checking if the array was already sorted in which case the best case running time would be T( n ).
How does this relate to your question about the practical realisations of these bounds? Well, unfortunately, O( ) notation hides constants which real-world implementations have to deal with. So although we can say that, for example, for a T(n^2) operation we have to visit every possible pair of elements, we don't know how many times we have to visit them (except that it's not a function of n). So we could have to visit every pair 10 times, or 10^10 times, and the T(n^2) statement makes no distinction. Lower order functions are also hidden - we could have to visit every pair of elements once, and every individual element 100 times, because n^2 + 100n = T(n^2). The idea behind O( ) notation is that for large enough n, this doesn't matter at all because n^2 gets so much larger than 100n that we don't even notice the impact of 100n on the running time. However, we often deal with 'sufficiently small' n such that constant factors and so on make a real, significant difference.
For example, quicksort (average cost T(n.log n)) and heapsort (average cost T(n.log n)) are both sorting algorithms with the same average cost - yet quicksort is typically much faster than heapsort. This is because heapsort does a few more comparisons per element than quicksort.
This is not to say that O( ) notation is useless, just imprecise. It's quite a blunt tool to wield for small n.
(As a final note to this treatise, remember that O( ) notation just describes the growth of any function - it doesn't necessarily have to be time, it could be memory, messages exchanged in a distributed system or number of CPUs required for a parallel algorithm.)
Comment: ... I care... (Math major)
Comment: On a programming site, we explain big-O as how programmers use it. Mathematically, of course, that's not the correct way, but nobody (on this site) cares. :)
Comment: I care too. Most of the answers here say that O(n^2) means "proportional to n^2". This is an abuse of notation. One could argue that by persistently abusing it, programmers have redefined Big-O to mean the same as Big-Theta. I feel that this is unfair to programmers' *potential* to understand what they're talking about, even if it accurately reflects the *current* ignorance of the average code monkey ;-)
Comment: +1 for the asymptotic upper-bound bit. None of the other popular answers seemed to touch on that.
Answer: The way I describe it to my nontechnical friends is like this:
Consider multi-digit addition.  Good old-fashioned, pencil-and-paper addition.  The kind you learned when you were 7-8 years old.  Given two three-or-four-digit numbers, you can find out what they add up to fairly easily.
If I gave you two 100-digit numbers, and asked you what they add up to, figuring it out would be pretty straightforward, even if you had to use pencil-and-paper.  A bright kid could do such an addition in just a few minutes.  This would only require about 100 operations.
Now, consider multi-digit multiplication.  You probably learned that at around 8 or 9 years old.  You (hopefully) did lots of repetitive drills to learn the mechanics behind it.
Now, imagine I gave you those same two 100-digit numbers and told you to multiply them together.  This would be a much, much harder task, something that would take you hours to do - and that you'd be unlikely to do without mistakes.  The reason for this is that (this version of) multiplication is O(n^2); each digit in the bottom number has to be multiplied by each digit in the top number, leaving a total of about n^2 operations.  In the case of the 100-digit numbers, that's 10,000 multiplications.
Comment: This is actually a great explanation of describing how different algorithms can take more time - although there's a difference here in which the algorithms (addition and multiplication) produce different results. Also a thing you left out, is that after multiplying these 2x 100 digit numbers (that is all the different parts), you're still left with having to add them all up (that's 10,000 numbers, some very large) - so your "algorithm" suddenly becomes O(scary) - I'm not good on this subject, which is why I read the question through.
Answer: No, an O(n) algorithm does not mean it will perform an operation on each element. Big-O notation gives you a way to talk about the "speed" of you algorithm independent of your actual machine.
O(n) means that the time your algorithm will take grows linearly as your input increase. O(n^2) means that the time your algorithm takes grows as the square of your input. And so forth.
Answer: The way I think about it, is you have the task of cleaning up a problem caused by some evil villain V who picks N, and you have to estimate out how much longer it's going to take to finish your problem when he increases N.
O(1) -> increasing N really doesn't make any difference at all
O(log(N)) -> every time V doubles N, you have to spend an extra amount of time T to complete the task. V doubles N again, and you spend the same amount.
O(N) -> every time V doubles N, you spend twice as much time.
O(N^2) -> every time V doubles N, you spend 4x as much time. (it's not fair!!!)
O(N log(N)) -> every time V doubles N, you spend twice as much time plus a little more.
These are bounds of an algorithm; computer scientists want to describe how long it is going to take for large values of N. (which gets important when you are factoring numbers that are used in cryptography -- if the computers speed up by a factor of 10, how many more bits do you have to use to ensure it will still take them 100 years to break your encryption and not just 1 year?)
Some of the bounds can have weird expressions if it makes a difference to the people involved. I've seen stuff like O(N log(N) log(log(N))) somewhere in Knuth's Art of Computer Programming for some algorithms. (can't remember which one off the top of my head)
Answer: One thing that hasn't been touched on yet for some reason:
When you see algorithms with things like O(2^n) or O(n^3) or other nasty values it often means you're going to have to accept an imperfect answer to your problem in order to get acceptable performance.
Correct solutions that blow up like this are common when dealing with optimization problems.  A nearly-correct answer delivered in a reasonable timeframe is better than a correct answer delivered long after the machine has decayed to dust.
Consider chess:  I don't know exactly what the correct solution is considered to be but it's probably something like O(n^50) or even worse.  It is theoretically impossible for any computer to actually calculate the correct answer--even if you use every particle in the universe as a computing element performing an operation in the minimum possible time for the life of the universe you still have a lot of zeros left.  (Whether a quantum computer can solve it is another matter.)
Answer:
And does somebody have to smoke crack to write an O(x!)?

No, just use Prolog. If you write a sorting algorithm in Prolog by just describing that each element should be bigger than the previous, and let backtracking do the sorting for you, that will be O(x!). Also known as "permutation sort".
Answer: The "Intuitition" behind Big-O
Imagine a "competition" between two functions over x, as x approaches infinity: f(x) and g(x).
Now, if from some point on (some x) one function always has a higher value then the other, then let's call this function "faster" than the other.
So, for example, if for every x > 100 you see that f(x) > g(x), then f(x) is "faster" than g(x).
In this case we would say g(x) = O(f(x)). f(x) poses a sort of "speed limit" of sorts for g(x), since eventually it passes it and leaves it behind for good.
This isn't exactly the definition of big-O notation, which also states that f(x) only has to be larger than C*g(x) for some constant C (which is just another way of saying that you can't help g(x) win the competition by multiplying it by a constant factor - f(x) will always win in the end). The formal definition also uses absolute values. But I hope I managed to make it intuitive.
Answer: I like don neufeld's answer, but I think I can add something about O(n log n).
An algorithm which uses a simple divide and conquer strategy is probably going to be O(log n).  The simplest example of this is finding a something in an sorted list.  You don't start at the beginning and scan for it.  You go to the middle, you decide if you should then go backwards or forwards, jump halfway to the last place you looked, and repeat this until you find the item you're looking for.
If you look at the quicksort or mergesort algorithms, you will see that they both take the approach of dividing the list to be sorted in half, sorting each half (using the same algorithm, recursively), and then recombining the two halves.  This sort of recursive divide and conquer strategy will be O(n log n).
If you think about it carefully, you'll see that quicksort does an O(n) partitioning algorithm on the whole n items, then an O(n) partitioning twice on n/2 items, then 4 times on n/4 items, etc... until you get to an n partitions on 1 item (which is degenerate).  The number of times you divide n in half to get to 1 is approximately log n, and each step is O(n), so recursive divide and conquer is O(n log n).  Mergesort builds the other way, starting with n recombinations of 1 item, and finishing with 1 recombination of n items, where the recombination of two sorted lists is O(n).
As for smoking crack to write an O(n!) algorithm, you are unless you have no choice.  The traveling salesman problem given above is believed to be one such problem.
Comment: Quicksort can't guarantee that it partitions equally. In the worst case, it repeatedly divides into partitions of size (k-2) and (1), so it's O(n^2). In the most naive qsort, the worst case is sorted data! A suitably tweaked algorithm makes it hard to construct the worst case, though.
Comment: My wrinkle on what you've said is 1) your explanation of searching is good (except there needs to be a better word than "log" for 8-year-olds), and 2) I just say sorting is repeated search - for each of n items, you need to search for where it goes and stick it in.
Answer: Think of it as stacking lego blocks (n) vertically and jumping over them.
O(1) means at each step, you do nothing. The height stays the same.
O(n) means at each step, you stack c blocks, where c1 is a constant.
O(n^2) means at each step, you stack c2 x n blocks, where c2 is a constant, and n is the number of stacked blocks.
O(nlogn) means at each step, you stack c3 x n x log n blocks, where c3 is a constant, and n is the number of stacked blocks.
Answer: Most Jon Bentley books (e.g. Programming Pearls) cover such stuff in a really pragmatic manner. This talk given by him includes one such analysis of a quicksort.
While not entirely relevant to the question, Knuth came up with an interesting idea: teaching Big-O notation in high school calculus classes, though I find this idea quite eccentric.
Answer: To understand O(n log n), remember that log n means log-base-2 of n.  Then look at each part:
O(n) is, more or less, when you operate on each item in the set.
O(log n) is when the number of operations is the same as the exponent to which you raise 2, to get the number of items.  A binary search, for instance, has to cut the set in half log n times.
O(n log n) is a combination – you're doing something along the lines of a binary search for each item in the set.  Efficient sorts often operate by doing one loop per item, and in each loop doing a good search to find the right place to put the item or group in question.  Hence n * log n.
Comment: Well, it really doesn't matter too much what the base is; with Big-O notation you generally factor out all the constants.  It's the pattern of the algorithm, not the particular base that matters.
Comment: Is that right? I always thought an unadorned log meant log to base e, at least it does in maths.  Log to base 2 would be written as log2 n (with that 2 subscripted of course, something I don't know how to do in comment fields yet.
Comment: For this purpose it doesn't matter, since an algorithm is O(log2(n)) iff it's O(log10(n)) etc
Comment: as far as I remember: log is to base 10. ln is to base e.
Comment: In mathematical notation, "log" means log base 10.  In computer science I've often seen it assumed to mean log base 2.
Answer: Just to respond to the couple of comments on my above post:
Domenic - I'm on this site, and I care. Not for pedantry's sake, but because we - as programmers - typically care about precision. Using O( ) notation incorrectly in the style that some have done here renders it kind of meaningless; we may just as well say something takes n^2 units of time as O( n^2 ) under the conventions used here. Using the O( ) adds nothing. It's not just a small discrepancy between common usage and mathematical precision that I'm talking about, it's the difference between it being meaningful and it not.
I know many, many excellent programmers who use these terms precisely. Saying 'oh, we're programmers therefore we don't care' cheapens the whole enterprise.
onebyone - Well, not really although I take your point. It's not O(1) for arbitrarily large n, which is kind of the definition of O( ). It just goes to show that O( ) has limited applicability for bounded n, where we would rather actually talk about the number of steps taken rather than a bound on that number.
Answer: Tell your eight year old log(n) means the number of times you have to chop a length n log in two for it to get down to size n=1 :p
O(n log n) is usually sorting
O(n^2) is usually comparing all pairs of elements
Answer: Suppose you had a computer that could solve a problem of a certain size.  Now imagine that we can double the performance a few times.  How much bigger a problem can we solve with each doubling?
If we can solve a problem of double the size, that's O(n).
If we have some multiplier that isn't one, that's some sort of polynomial complexity.  For example, if each doubling allows us to increase the problem size by about 40%, it's O(n^2), and about 30% would be O(n^3).
If we just add to the problem size, it's exponential or worse.  For example, if each doubling means we can solve a problem 1 bigger, it's O(2^n).  (This is why brute-forcing a cipher key becomes effectively impossible with reasonably sized keys:  a 128-bit key requires about 16 quintillion times as much processing as a 64-bit.)
Answer: Remember the fable of the tortoise and the hare (turtle and rabbit)?
Over the long run, the tortoise wins, but over the short run the hare wins.
That's like O(logN) (tortoise) vs. O(N) (hare).
If two methods differ in their big-O, then there is a level of N at which one of them will win, but big-O says nothing about how big that N is.
Answer: To remain sincere to the question asked I would answer the question in the manner I would answer an 8 year old kid
Suppose an ice-cream seller prepares a number of ice creams ( say N ) of different shapes arranged in an orderly fashion.
You want to eat the ice cream lying in the middle
Case 1 : - You can eat an ice cream only if you have eaten all the  ice creams smaller than it
You will have to eat half of all the ice creams prepared (input).Answer directly depends on the size of the input
Solution will be of order o(N)
Case 2 :- You can directly eat the ice cream in the middle
Solution will be O(1)
Case 3 : You can eat an ice cream only if you have eaten all the ice creams smaller than it and each time you eat an ice cream you allow another kid (new kid everytime ) to eat all his ice creams
Total time taken would be N + N + N.......(N/2) times
Solution will be O(N2)
Answer: log(n) means logarithmic growth. An example would be divide and conquer algorithms. If you have 1000 sorted numbers in an array ( ex. 3, 10, 34, 244, 1203 ... ) and want to search for a number in the list (find its position), you could start with checking the value of the number at index 500. If it is lower than what you seek, jump to 750. If it is higher than what you seek, jump to 250. Then you repeat the process until you find your value (and key). Every time we jump half the search space, we can cull away testing many other values since we know the number 3004 can't be above number 5000 (remember, it is a sorted list).
n log(n) then means n * log(n).
Answer: I'll try to actually write an explanation for a real eight year old boy, aside from technical terms and mathematical notions.

Like what exactly would an O(n^2) operation do?

If you are in a party, and there are n people in the party including you. How many handshakes it take so that everyone has handshaked everyone else, given that people would probably forget who they handshaked at some point.
Note: this approximate to a simplex yielding n(n-1) which is close enough to n^2.

And what the heck does it mean if an operation is O(n log(n))?

Your favorite team has won, they are standing in line, and there are n players in the team. How many hanshakes it would take you to handshake every player, given that you will hanshake each one multiple times, how many times, how many digits are in the number of the players n.
Note: this will yield n * log n to the base 10.

And does somebody have to smoke crack to write an O(x!)?

You are a rich kid and in your wardrobe there are alot of cloths, there are x drawers for each type of clothing, the drawers are next to each others, the first drawer has 1 item, each drawer has as many cloths as in the drawer to its left and one more, so you have something like 1 hat, 2 wigs, .. (x-1) pants, then x shirts. Now in how many ways can you dress up using a single item from each drawer.
Note: this example represent how many leaves in a decision-tree where number of children = depth, which is done through 1 * 2 * 3 * .. * x
Comment: @PavanKatepalli the solution didn't say "random", it specified how many, if you keep reading `how many times, how many digits are in the number of the players n.`, the number of digits in a number is its log to the base 10, given it's a positive integer.
Comment: the handshake example doesn't make sense. It would be O(n) directly correlated to the number of players on the team. Why would you shake someone's hand a random amount of times?

Big-O for Eight Year Olds?


Nethack is failing to load due to a dungeon faliure in nhdat file

Question: I start up nethack, then I enter my name and roles, and a window opens up saying "oops.", then another saying "Program initialization failed", then "Report the following error to"email@example.com", then "Cannot open dungeon desc. from file "C:\Users[MyName]\Desktop\nhdat" file!" and closes, leaving a document called "paniclog" which repeats "3.4.3 20140306: panic Cannot open dungeon description - "dungeon" from
"C:\Users[MyName]\Desktop\nhdat" file!" three times. Is there an alternative download that I can get? I have already re-downloaded it three times already.
Comment: Have you edited your nhdat file, and is that the directory that you are running the game from?
Answer: I was able to replicate the same problem you have by only having the Nethack executable with the keymapper's .dll's on a folder.
As stated on the download page for the Windows port:

Step 0:
Promise to read Step 2 before telling us the game will not start.
  Thank you.
Step 2: unpack.
These files can be unpacked with any standard unzipping utility, which should be used when you have set your current directory to the location where you want to place NetHack. Some people have attempted to run the game from inside an unzip utility - this will not work. You must extract the contents of the .zip file to a new folder and run the game from that folder. Do not remove (or copy) the executable from the folder (you can create a shortcut to it instead).

The problem is most likely that you didn't read the manual. Just unpack the archive to a real folder and run Nethack (alongside a plethora of other files) from that folder.
Answer: Have you tried reporting it to the email address suggested? It's not likely to yield an immediate fix, but you never know, and worst case, they might fix the bug (if it isn't already fixed) and release a new version one day. (Don't hold your breath though, it's been years since the last release)
Comment: I was about to say, regardless of what the dev team claim, Nethack vanilla is pretty much dead. He'd be better off going with UnNethack or Nethack4
Comment: Fair. I should try one of those myself.


How does temporary magic item attunement work?

Question: I have a wizard who has a Pearl of Power.  According to the rules, it looks like he should be able to, on each day, take a short rest to attune to it, use it to recover a spell slot, then take a short rest to re-attune to his usual other magic item.
This seems to me kind of a weasel workaround to effectively get attunement to 4 magic items, but looks legal.  Is there any reason (other than time management) that this doesn't work?
Answer: Well, it'll take four short rests, not two, but otherwise, yes, this works.

An
  item
  can
  be
  attuned
  to
  only
  one
  creature
  at
  a
  time,
  and
  a
  creature
  can
  be
  attuned
  to
  no
  more
  than
  three
  magic
  items
  at
  a
  time.
  Any
  attempt
  to
  attune
  to
  a
  fourth
  item
  fails;
  the
  creature
  must
  end
  its
  attunement
  to
  an
  item
  first.

So at the start of the day, the wizard has to end his attunement to one of his other items before he can attune to the Pearl of Power. Similarly, after using the Pearl, the wizard can't just attune to the other item; he has to end his attunement to the Pearl first.

A
  creature's
  attunement
  to
  an
  item
  ends
  if
  the
  creature
  no
  longer
  satisfies
  the
  prerequisites
  for
  attunement,
  if
  the
  item
  has
  been
  more
  than
  100
  feet
  away
  for
  at
  least
  24
  hours,
  if
  the
  creature
  dies,
  or
  if
  another
  creature
  attunes
  to
  the
  item.
  A
  creature
  can also
  voluntarily
  end
  attunement
  by
  spending
  another
  short
  rest
  focused
  on
  the
  item,
  unless
  the
  item
  is
  cursed.

And in order to end his attunement, he has to:

Not be a spellcaster, which is basically impossible.
Keep it more than 100 feet away for 24 hours, which breaks the point of this.
Die (Yikes!)
Have another creature attune to the item in question. This could work, but it'd require them to spend a short rest, so he'd have to wait 1 hour and then take his short rest to attune to the other item.
Take a short rest himself.
Comment: I think it might be possible for 1 player to attune to another's item and that player to attune to a new item during the same short rest, depending on how the DM rules on the exact timing of (1) number of attuned items check and (2) attunement completion.  If (1) and (2) happen at the same time, the other player can start their attunement 1 min earlier so that as the attunement comes to an end, they have just been reduced to 3 items (so 2 rests).  Although, since this is a little on the abusive, but legal side of things, I am okay the idea that it should be the harder option when ambiguous.
Answer: It is completely legal. He could even use several pearls of power every day.
The limiter is the availability of 1-hour intervals where he can do the attunement.
Adventurers often don't have the luxury of choosing their schedule. This particular DM not-so-often pulls quantum ogres from his hat to derail the R&R of the party. An adventure should keep the adventurers on their toes.
And he needs an extra 1-hour interval to de-attune before reatunning with another item.


Do there exist equivariant sheafs that are not equivariant vector bundles?

Question: For $F \subset G$ two algebraic groups, consider a homogeneous space $H$ of the form $G/F$. Now every vector bundle over $H$ is a coherent sheaf, but the converse is not true. What happens in the equivariant setting? Do there exist equivariant sheafs that are not equivariant vector bundles?
Answer: I assume that the algebraic group $G$ is smooth and connected, and that you are asking about equivariance for the natural action of $G$ on $H$.  There is a quotient morphism $q:G\to H$ that is $G$-equivariant and faithfully flat.  Thus, to prove that a $G$-equivariant coherent sheaf on $H$ is locally free, it suffices to check that the pullback $G$-equivariant coherent sheaf on $G$ is locally free.  Since $G$ is smooth, for every coherent sheaf $\mathcal{F}$ on $G$, there exists a maximal open subscheme $U$ of $G$ on which $\mathcal{F}$ is locally free (possibly zero), and $U$ is dense in $G$.  If $\mathcal{F}$ is $G$-equivariant, then $U$ is $G$-invariant.  The only dense $G$-invariant open subset of $G$ is all of $G$.  Thus every $G$-equivariant coherent sheaf on $G$ is locally free.  Therefore every $G$-equivariant coherent sheaf on $H$ is locally free.
Edit.  As Sasha points out, it is unnecessary to pullback to $G$ (it just makes it easier for me to think about).
Comment: Yes, and moreover it is equivalent to representations of $F$ (the equivalence is given by taking a fiber of  a vector bundle at some chosen point of $H$).
Comment: Jason, what was the reason of considering the pullback of $\mathcal{F}$ to $G$? You could use the same argument directly on $H$ --- since the action of $G$ on $H$ is transitive the only $G$-invariant open subset of $H$ is all $H$.
Comment: . . . just a thought though - does this mean that the category of equivariant vector bundles is an abelian category?


What is meaning and correct grammar of "looking to lock up" expression?

Question: I have come across a sentence "I was talking about the fourth quarter of game seven, when you're looking to lockup a championship...". I checked in all available dictionaries and did not find meaningful explanation. From a context I guessed it means to win a championship prematurely according to some tournament system, but there are still doubts. Also Google returned me a page that said "Porsche Looking to Lock Up World Championship in Shanghai" without verb be before "Looking". So my questions are: did I guess the meaning correctly and what is correct grammar to use the expression (with/without be)?
Answer: You have it right: "when you're looking" has the verb to be before looking. The headline "Porsche Looking to" leaves out the word is, and it means they are seeking to complete the championship by winning it solidly: The auto maker is in pursuit of a quick finish to the race
Definition of Look 2.c. To turn one's expectations:

looked to us for a solution.

Both your examples have the same meaning: aiming to (looking to) achieve or own (lock up).
Comment: Thanks for your answer, but it is still not clear about omitting "be/is" in the second expression. Is it some sort of a gerund clause? Could you point me to a related grammar topic?
Comment: Headlines Short.  Words Stingy. Universal Truth: Less More. Your search found a sportscar magazine headline, and headlines break rules to save space and to entice readers to read further. No gerund is used, but the obvious words are left out to save space: Porsche (is actively in the process of) Looking to Win.


Could the d-factor still be changed, to revert to more centralized block production by IOG?

Question: Nothing is mentioned anywhere if, and according to which policy, IOG can move the d-"slider" in the other direction, to again start producing more centralized blocks whenever they deem this necessary. Probably a question only Charles or Duncan can answer.
Answer: Cardano has three different pillars of decentralization:
The first pillar: block production. Once d hit 0, this pillar was fully decentralized.
The second pillar: networking. It means how nodes find each other and pass on this information. Currently, this is a topology file and it will be replaced by P2P discovery.
The third pillar: governance. The way to vote on all protocol parameters (like d) and updates and access fundings of the treasury.
So to answer your question: yes, theoretically, it would currently be possible to increase the d-parameter again. But should IO do so, it would certainly be a disastrous signal.
Comment: The d-parameter was introduced with the hard-fork from Byron to Shelly.
This was implemented for the purpose of slowly allowing public stake-pools to produce blocks.
Answer: As long as the facility is available in the code, it is technically possible for the process to be reversed.
Answer: And as Charles Hoskinson mentioned several times if the community decides in the future to vote for a particular proposal via Catalyst and the proposal is accepted then will be implemented.
So when Catalyst is fully deployed and we have full decentralization (most probably around or after 2025 based on the roadmap for Voltaire) then the community can vote for this proposal if the proposal is submitted. If for some reason this proposal is accepted (which is highly unlikely) technically can be implemented again.


Salesforce Files - Is it possible to link a file with Case + specific user and skip it from Content Document link API call?

Question: We've a use case where our customer wants us to link a File record to Case but not fetch it via Content Document link API call i.e. mark it private for selective internal Salesforce users. In nutshell, is it possible to have privacy settings specific to user on Files linked to Case records?
Answer: You can use the ShareType field on ContentDocumentLink to control the access to file.
Additionally, you can move your files from Case to a Child Custom Object and control access of files using the record access on this child object records.
You would have to write trigger on ContentDocumentLink to update access and moving file to child object.


Where can I ask how to use a specific hypothesis test in R?

Question: I'd like to know where on Stack Exchange I should ask about how to use a specific hypothesis test on R and where to ask if my code tests do what I would like to without theoretical foundation.
Answer: There are two components to what you want to know.

Which statistical test is appropriate for your specific problem?
How to write code to carry out the desired statistical test?

Question (1) is on-topic here, because it is about statistics.
Question (2) is off-topic here, because it is solely about writing code. Depending on the nature of the programming problem you face, there are several sites that could be a good fit. You'll need to read the Help Center for each and make a choice about which site is best.
Comment: It's not entirely clear to me what your specific question is/would be, so I'm not sure of the best place to ask it.
Comment: Unfortunately, "is my code correct?" questions don't fare well anywhere, even on Stack Overflow. The best kind of question there identifies a specific problem with your code and asks how to fix it. Other way round, there are many, many users of statistics active on Stack Overflow. It's my impression, for example, that it has long since superseded R-help as the best single place to ask questions on R code.  Just now a check on the R tag reports 430,924 questions -- and naturally the number will be higher when anyone reads this.
Comment: @DaviAmérico, I have trouble imagining what such a question would be.  There really isn't much of anything you need to do in R to "do a test correctly".  R does all the work for you, & it's set up that way intentionally, eg, `t.test(x, y)`, will run a t-test correctly w/o you having to worry about how R is calculating the pooled SD. Maybe you could ask, 'how can I check that I got the right answer?' or something like that.
Comment: I was thinking about put it on stack overflow but I think there aren't many people using statistics there.
Comment: just look over if my code is doing the test correctly


Confidence intervals of positive parameters reaching into negatives

Question: Suppose I want to estimate the proportion parameter for a binomial distribution, and my method for constructing a 95% confidence interval (e.g. MLE +- 1.96 SDs) gives an interval of let's say (-.1, .3). Then what is the standard practice? I mean it's not wrong by my understanding of what a confidence interval is, but on the other hand would it be better to truncate the interval? So if the normal approximation gives (a,b), the CI should be (max{a,0},min{b,1})
Answer: You can look at the Wikipedia article on confidence intervals for binomial proportions. About half a dozen methods
are in common use.
In elementary US statistics books
the 95% Wald interval (based on a limiting argument) was used for some years before it was shown to have poor
coverage probability for small $n$ (and also to give
interval endpoints outside $(0,1)$ for very small or
very large observed proportions $\hat p = x/n).$
For 1 success in 10 trials the 95% Wald interval is
$\hat p \pm 1.96\sqrt{\frac{\hat p(1-\hat p)}{n}},$
which computes to $(-0.086, 0.286)$ and would usually
get truncated to $(0, 0.286),$ perhaps with a footnote.
[Computation in R.]
n = 10;  x = 1;  hat.p = x/n
hat.p + qnorm(c(.025,.975))*sqrt(hat.p*(1-hat.p)/n)
[1] -0.08593851  0.28593851

One kind of interval is easy compute if you have
access to computation of quantiles of
beta distributions. For this interval, one uses quantiles 0.025 and 0.975 of $\mathsf{Beta}(x+.5, n-x+.5).$ This is called
a 95% Jeffreys CI because it is derived by a Bayesian argument from a noninformative Jeffreys prior distribution. Because beta distributions have support $(0,1),$ endpoints of these intervals are always between $0$ and $1.$ For my example above, the
95% Jeffreys confidence interval is $(0.011, 0.381).$
qbeta(c(.025,.975), 1.5, 9.5)
[1] 0.01101167 0.38131477

Notes: (1) Some of the types of CIs mentioned in the Wikipedia article are tedious to compute or not widely implemented in statistical software. One easily computed improvement on the Wald interval, mentioned there is due to Agresti and Coull, although it can also occasionally give endpoints outside of $(0,1),$ as below:
n = 10;  x = 1;  hat.p = (x+2)/(n+4)
hat.p + qnorm(c(.025,.975))*sqrt(hat.p*(1-hat.p)/(n+4))
[1] -0.0006521887  0.4292236173

(2) Reference 4 (by Brown et al.) in the Wikipedia article has an accessible discussion of coverage probabilities of various styles of binomial confidence intervals.
Comment: As your last reference documents the Jeffreys interval also has frequentist interpretations.
Answer: There are several ways to construct confidence intervals for proportion parameters which have better properties than the normal approximation ("Wald-type" confidence interval) which you have mentioned.
A relatively simple choice that avoids "overshoot", is to compute a Wald-type  confidence interval for the log-transformed proportion and to transform it then back to the original scale.
Let $X \sim \text{Bin}(n, \pi)$ and $x$ be a realization of $X$. The maximum likelihood estimator (MLE) of $\pi$ is
$$\hat{\pi} = \frac{x}{n}$$
with standard error
$$\text{se}(\hat{\pi}) = \sqrt{\frac{\hat{\pi}(1 - \hat{\pi})}{n}}.$$
By the invariance of the MLE, the MLE of $\log\pi$ is
$$\widehat{\log\pi} = \log\frac{x}{n}.$$
Application of the delta method leads to
$$\text{se}(\widehat{\log\pi}) = \sqrt{\frac{1 - \hat{\pi}}{\hat{\pi}n}}
= \sqrt{\frac{1}{x} - \frac{1}{n}}.$$
So a 95% confidence interval for $\log\pi$ is given by
$$\widehat{\log\pi} \pm z_{0.975} \cdot \text{se}(\widehat{\log\pi}),$$
with $z_{0.975}$ the 0.975 quantile of the standard normal distribution. Transforming this confidence interval with the exponential function yields an improved confidence interval for the proportion $\pi$.
x <- 3
n <- 20
p <- x/n

## standard CI
sep <- sqrt(p*(1 - p)/n)
(CI1 <- p + c(-1, 1)*qnorm(0.975)*sep)
[1] -0.006490575  0.306490575

## improved CI
logp <- log(p)
selogp <- sqrt(1/x - 1/n)
(CI2 <- exp(logp + c(-1, 1)*qnorm(0.975)*selogp))
[1] 0.05284509 0.42577277

Answer: The problem is that for you are trying to apply the CLT, but you have no control over the rate of convergence. Your assumption that the CLT sufficiently applies so that the confidence interval is MLE +/- 1.96 * SD's is not true if you are getting a CI of (-0.1, 0.3). In fact, it is well known that CLT convergence in the binomial case is quite slow for p close to 0 and 1.
Truncating the CI like you want will not result in a 95% CI. Either get more data so the CI is contained in [0,1] (for p close to 0 or 1, you'll need a lot of data, rates of convergence to the CLT are quite slow) or use a Bayesian technique.
See https://math.unm.edu/~james/Agresti1998.pdf
See https://towardsdatascience.com/five-confidence-intervals-for-proportions-that-you-should-know-about-7ff5484c024f
Answer: Definitely, you can and should truncate the CI. It is standard practice.
If the un-truncated CI contains the true parameter 95% of the time, then the truncated CI will also contain the true parameter 95% of the time (because you are only removing values that are impossible). Better than truncating the asymptotic CI is to use one of the methods for small sample sizes. A comparison of different methods can be seen here.
Comment: "standard practice" I would call an exaggeration as it's been very widely known for much more than 20 years that truncation is a poor ad hoc method and there are better methods which are widely publicised and implemented. That truncation is still common practice wouldn't surprise me. This was the first answer, but it has been superseded by better answers. Suggesting a different method for small samples raises the question of when samples are no longer small.
Comment: "the truncated CI will also contain the true parameter 95% of the time (because you are only removing values that are impossible)" --intuitively this feels untrue, do you have a proof?
Comment: @SimonN Yes. Let LL be the lower limit and UL be the upper limit. A is the event $LL<\theta<UL$. Suppose the event occurs. Since it is known that $0\le \theta \le 1$ always, it follows that $B=max(LL,0) \le \theta \le min(UL,1)$ also occurs. The event B is the intersection of the event A and an event that always occurs. Conversely, if B occurs, then so does A. So, the expected value of the indicator function of the event  A is equal to the expected value of the indictor function of the event B. That's equivalent to the statement that the probabilities are equal.


Negative energy eigenvalues?

Question: If we have a free particle with a wave function consisting of a sine wave/exponential wave moving in the negative-x direction, its wave function will be:
$$|\psi\rangle=Ae^{i(kx+\omega t)}$$
The energy eigenvalue for this wavefunction will be $-\hbar\omega$:
$$\hat E|\psi\rangle=i\hbar\dfrac{\partial}{\partial t}(Ae^{i(kx+\omega t)})=-\hbar\omega Ae^{i(kx+\omega t)}=-\hbar\omega|\psi\rangle$$
What is the significance of this and how is it different from a wave going in the other direction?
Comment: What you've proven is that that isn't actually the wavefunction of a particle moving to the left, it's $e^{-i(kx+\omega t)}$. You can instead think of what you have as a particle moving to the right backwards in time, sort of.
Answer: $i\hbar \frac{\partial}{\partial t}$ is not the energy operator.  For a free particle of mass $m$, the energy operator (in position space) is
$$ \hat E = -\frac{\hbar^2}{2m} \frac{\partial^2}{\partial x^2}$$
Applying that to your wave function gives
$$\hat E \psi = -\frac{\hbar^2}{2m}(-k^2)\psi = \frac{\hbar^2k^2}{2m}\psi$$
so the eigenvalues of the free particle energy operator are non-negative.

Separately, Schrodinger's equation tells us that
$$i\hbar \frac{\partial \psi}{\partial t} = \hat E \psi$$
If we plug in your chosen wave function, then we find that
$$-\hbar \omega \psi = \frac{\hbar^2 k^2}{2m} \psi$$
Because $\frac{\hbar^2 k^2}{2m}$ is nonnegative, it follows that $\omega$ must be negative.  In other words, you have written down a negative frequency plane wave.
Conventionally we avoid this issue by working only with positive frequency solutions.  If $\psi$ is an energy eigenstate, then
$$\psi \propto e^{-i\omega t}$$
where $\omega$ is taken to be strictly positive.  In such a convention, it follows that $E = \hbar \omega$.  If you choose not to follow this convention, then you find that $E = \pm \hbar \omega$ depending on the sign in the exponent $e^{\mp i \omega t}$.
Answer: This is one of those questions whose answer depends a lot on the depth you want.
Facetious answer, that will look less stupid in a few paragraphs: you've affected $t\to -t$, so the particle is moving backwards in time.
We can shift energies by an arbitrary additive constant $E_0$, which is achieved in QM with the unitary transformation of multiplying wavefunctions by $\exp -iE_0 t/\hbar$. So there isn't much physical significance in the positive-negative energy distinction; we can only say how much energy a state has relative to another one.
If you take relativity into account, it's easy to run into cousins of the Schrödinger equation such as the Klein-Gordon equation, which unlike Schrödinger have a solution symmetry $\psi\to\psi^\ast$. This has the effect of changing the sign of energy, and understanding these negative-energy states was a big headache for a while. This is because many systems have no highest energy, and if you allow a sign change in eigenenergies there won't be a ground state either.
Eventually the Dirac equation gave us a slightly better understanding of "negative-energy" states by associating them with antimatter, whose energy measure requires a sign change to make sense of energy conservation in such events as annihilation or pair creation. This means the energies end up positive even for antimatter, but you wouldn't know that from the $\exp i\omega t$ form of its part of the Dirac spinor. In view of CPT invariance, one can say an antiparticle is like a particle moving backwards in time. So the shortest answer I could have given to your question is "it's antimatter".
But that would leave out one further detail.
The above illustrated why we ended up with quantum field theory. It's possible in an expanding universe for an initial $\exp -i\omega t$ dependence to become of the form $\alpha \exp -i\omega \eta + \beta \exp i\omega \eta$, $\eta$ the conformal time. (This is an example of a Bogoliubov transformation.) The $\beta$ term yields particle creation, because the wave's evolution hasn't "stayed in sync" with that of the vacuum definition. As a result, we get a particle density proportional to $|\beta|^2$.
Answer:
its wave function will be: $|ψ\rangle=Ae^i(kx+ωt)$

For a stationary state (energy eigenstate), the time dependence is $|\psi(t)\rangle = |\psi\rangle e^{-i\frac{E}{\hbar}t}$ so that
$$H|\psi(t)\rangle = i\hbar\frac{\partial}{\partial t}|\psi(t)\rangle =  i\hbar\frac{\partial}{\partial t}|\psi\rangle e^{-i\frac{E}{\hbar}t} = E|\psi(t)\rangle$$
It follows that the wavefunction of a free particle with definite momentum in the negative $x$ direction is
$$\psi(x,t) = e^{-i(kx + \omega t)}$$
where $\omega \equiv \frac{\hbar k^2}{2m}$.  Then
$$P_x\psi(x,t) = -i\hbar \frac{\partial}{\partial x}\psi(x,t) = -\hbar k\, \psi(x,t)$$
$$H\psi(x,t) = -\frac{\hbar^2}{2m} \frac{\partial^2}{\partial x^2}\psi(x,t) = \frac{\hbar^2 k^2}{2m}\psi(x,t) = \hbar\omega\,\psi(x,t)$$

Negative energy eigenvalues?


What is the origin of the phrase "take it from the top?"

Question: "Take it from the top" is often used in musical rehearsals to mean "start at the beginning."  Where did this phrase come from?
Answer: Here's what the Oxford English Dictionary says:

Music colloq. (orig. Jazz). from the top: from the beginning of a piece of music, typically for a second or subsequent time; also in extended use. Freq. in to take it from the top : to start (over) at the beginning.
1940   Gramophone Nov. 140/3 (title of song)    Take it from the top.

However, Robert S. Gold's A Jazz Lexicon (1964, read online) says it's earlier by a few years:

top (down), from the, [by analogy with reading sheet music; current since c. 1930] See 1936 quot.; also, by extension, from the beginning of anything (to the end). — 1936 Metronome, Feb., p. 21. from the top down: playing an orchestration right through. —1956 Eddie Condon's Treasury of Jazz, p. 219. "Let's do this one more time from the top, gentlemen."

This also points out it can mean not only to start at the beginning, but also to keep going until you get to the end; to initiate a full run-through.
Comment: I've sent this antedating to the OED.
Answer: I think they're referring to the physical top of the song's or score's first page. I've always taken this literally, which seems to work.
Comment: This is correct but more of a comment than an answer.


check a checkbox and refresh the page, how to restore their state

Question: My problem is that when I try to check a checkbox and refresh the page, the checkbox returns to being uncheck. I am using Sharepoint 2010.
i want them to retain values
Comment: afaik you can't retain values after a refresh, even the ViewState only works for postback. so you'll have to save the value somewhere and set it on the page on load.
Answer: Not sure if this is possible, but the only idea comes to mind is to save values in the ViewState property as explained here


Home directory vs Working directory

Question: In unix like systems what is the difference between a home directory and working directory ?
Comment: Your home directory is where you go to rest between work sessions. Your working directory is where you are right now. Because unix systems are multitasking, each process has its own working directory; processes can change directories, too.
Answer: The home directory is a directory associated with a user name in the system's user account database. It's the 6th field in the entry returned by getent passwd some-user.
When you log in, the HOME environment variable is initialized from that value and applications use that variable or query the user database to know what your home directory is.
That directory is usually owned and writable by the corresponding user, and it's typically where applications store the user settings and where the user stores their files.
In shells, ~ expands to your home directory, and ~user to the home directory of user user.
The kernel has no notion of what a user name or home directory is. The home directory is entirely a user-space concept.
On the other hand, the working directory is an attribute of each process. It can be changed with the chdir(2)/fchdir(2) system calls (and the cd/pushd/popd commands in a shell) and queried using getcwd() or pwd in a shell. The current working directory is the base for finding a file using a relative path. A relative path (as in "foo/bar.txt") is relative to the current working directory of a process.
The working directory is inherited upon a fork and preserved upon execution of a command. For instance, ls lists the content of its working directory which is the same as the working directory of the shell that called it.
When a user logs in, the working directory of the first process that is run under his name is set to his home directory, and as a result, unless anything changes it, every process started under that login session will have the home directory as the current working directory.
shells don't start in the home directory, they start wherever the current directory was when they were executed, though shells started by a terminal emulator itself started by a window manager itself started by the login manager will likely start in the home directory since there's no reason why the window manager or terminal emulator would change their working directory.
Answer: A home directory is where most terminal emulators start when you open a shell. The working directory is where you are right now. You can usually go directly to the home directory with the command cd and you can find out what the working directory is with pwd.
Comment: The _"A home directory is where you start when you open a shell"_ part is wrong in general. It's only true for shells that are started from a process that happens to have the working directory set to the home directory (as is often the case for shells started by terminal emulators started by your window manager, or login shells, but doesn't have to).
Comment: @StéphaneChazelas: Thank you, I reworded the answer slightly. My intention was clarity at the expense of pedantry for users with the OP's perceived experience.
Comment: You can find out your home directory with `echo $HOME`

Home directory vs Working directory


How to add additional sensors [Arduino]

Question: I am new to Arduino.
I have currently connected a FSR sensor to the TOUT pin of ESP WROOM-02.
How do I add additional FSR sensor to ESP WROOM-02?
Comment: TOUT: it can be used to test the power-supply voltage of VDD3P3 (Pin3 and Pin4) and the input power voltage of TOUT (Pin6). These two functions cannot be used simultaneously. Why did you connect a FSR sensor to TOUT?
Answer: An FSR (Force Sensing Resistor) varies in resistance as force or pressure is applied.  Most often such devices are connected to the positive power rail and the ADC input of a embedded micro controller.  At the same time a second known fixed resistor is connected to the opposite power rail (ground) and the same ADC input.  This forms a resistor divider network where the ADC in the embedded micro controller can measure the force applied to the FSR by measuring the voltage of the resistor divider.
To measure 2 or more FSRs using the same ADC input, consider connecting one lead of each FSR to a digital input/output pin of the embedded micro controller. Then connecting the other lead of each FSR to the ADC input.  To measure the force on the 1st FSR, configure the connected digital pin as a high ouput using software.  So that all the other FSRs do not influence the measurement, configure all the other digital pins to have high impedance.  Often this can be done by programming these other digital pins as inputs.  Cycle through all FSRs in a similar fashion using software.

How to add additional sensors [Arduino]


Azure Hybrid connection error - Microsoft.Azure.Relay.AuthorizationFailedException - InvalidSignature

Question: I'm connecting an AWS EC2 SQL Database instance/server with an Azure Web app, using a Hybrid connection. It was working but had sporadic errors so I thought I'd delete the connection in Azure, re-create it, re-install Hybrid Connection Manager on the DB Server, and then reconnect it all.
So the recreated hybrid connection is identical to the old one, same names, same everything.
But now the Hybrid Connection Manager on the AWS DB Server shows as 'connected' but when I try to connect via the web app (or use Azure's diagnostics/check connection strings), then I get this error:

[Win32Exception (0x80004005): The specified network name is no longer
available]

If I go into Genie in the actual Web App and ask her to analyse the Hybrid connection, then I get this error:

The App Service instance that was using the Hybrid Connection has
encountered errors. The following errors were detected:
Exception Details
Microsoft.Azure.Relay.AuthorizationFailedException    InvalidSignature

On the AWS DB Server I can do a

Test-NetConnection -computer myservicebusname.servicebus.windows.net -Port 443

And that resolves and says it can connect.
I can't find this InvalidSignature error on internet searches so I'm at a bit of a loss how to fix it! Any ideas?
Answer: This error was due to an invalid DNS entry on a server in the AWS VPC that was resolving some internal domain names to the wrong IP. Do an nslookup [endpoint] on the machine the HCM is on to check this is being resolved correctly.
Also check there are no old references to the hybrid connections that you have missed - check the number of listeners for example and make sure it matches up - I had some old hanging references in random web apps that confused this issue.


Unsolvability of Quintic + equations from a logical perspective

Question: From what I understand, equations higher than the fourth degree cannot have a general solution. I am curious if there are logical reasons for this. By extending ZFC in some non-trivial way, could we possibly attain a solution?
   More generally, I am trying to understand what it means for a solution to 'not exist'. Do they truly not exist in any way, or do they not exist 'given our current mathematical systems'?
Comment: A solution to the general polynomial equation of a degree $n \geq 5$ always exists for some domains (it exists sometimes over $\mathbb{R}$, and always over $\mathbb{C}$, for example). What does not exist is a formula, using only elementary operations ($+, -, \times, \div, \sqrt{~}$), for the solutions of the general equation. So if a formula for the solution exists, it must use in someway a non-elementary function or operation.
Comment: Just to clarify your title and text, a quartic formula exists (although not very fun to use), but the general *quintic* is unsolvable by radicals.
Answer: It really is a case of "solutions truly don't exist" - at least, solutions of a specific form.
Here's the question, formulated roughly:

If $Q$ is a (non-degenerate) quinitic with rational coefficients, must $Q$ have a solution which can be expressed in terms of the arithmetic operations (plus, times, minus, divides) and $n$th roots, applied to rational numbers?

For a more precise statement of the question, look up "solvable by radicals."
Then Abel's Theorem is that the answer is no: there are quintics, all of whose solutions are not expressible in this form. In particular, they aren't weird quintics at all, on the face of things - I don't know why wikipedia doesn't give an explicit example, but one quintic with no solution which can be expressed by radicals is $$x^5-4x+2$$ (see page 27 of http://vc.bridgew.edu/cgi/viewcontent.cgi?article=1182&context=undergrad_rev).
EDIT: One take-away from all this is that we really shouldn't say "Quintics are unsolvable" - we need to specify what kind of "solution" we're asking for!

Think about it this way: clearly not every (nondegenerate) quadratic equation (with rational coefficients) has a rational solution - e.g. $x^2-2=0$. The unsolvability of the quintic is a statement of a similar form: there are quintics whose solutions lie outside a given "nice" class of numbers, specifically those which can be expressed in a certain way.
Answer: Also, complementing my comment, the nonexistence of a radical formula (that's how we call such a formula) follows from Galois Theory, applied to extensions of fields (the domains we're talking about) by roots of polynomials. We see what happens when we put those solutions inside the field, in terms of ''symmetry''. That symmetry is given by an algebraic structure called a Galois group.
A fundamental theorem of Galois Theory states that a polynomial has a radical solution formula if, and only if, the symmetry associated with it is nice enough (it's Galois group must be a solvable group). What is shown is that, for polynomials with degree $> 4$, the Galois group associated is never solvable (this has to do with something called the alternating group, in case you want to look at it).
Now, on a logical point of view. Well, once our current logical system implies the unsolvability by radicals of the higher degree polynomials, trying to force it would not result on a consistent system. We would need to relax certain axioms to the minimum point where we could postulate solvability by radicals (that minimum point must still have the necessary axioms to formulate what solvability by radicals is!) and get something consistent. My guess is that such point does not exist, or at least in a way that leaves the other parts of mathematics sufficiently untouched.
Also, as a philosophical note, our logic system, our fundamentals, are actually more ruled by mathematicians than rulers of mathematics. Reasons for it being this way is that it is sufficiently good to imply the validity of everything we ever proved to day and composed of axioms simple enough to not generate polemic over it. Finding an alternative logic system that fixed solvability of the quintics while breaking everything else on mathematics would be very undesired and certainly uninteresting for a great deal of the mathematical community.
Think of it as a choice: we must start mathematics from somewhere, so let's start from what gets us the most bang for the buck.
Comment: To comment on your third paragraph: you would need to go well below even Peano Arithmetic, and probably below the much *much* weaker theory $I\Sigma_1$, in order for "quintics are solvable" to be consistent. So yes, the vast majority of mathematics would have to go!
Comment: Not sure about etiquette, still learning to use this site, but both of these responses answered my question. Thank you


Magento transactional emails not working

Question: Magento transactional emails do not work, I am not sure If I set them up correctly. I added and customized transnational emails. I read somewhere, my contact information should be @websitename.com in order to work. Please advice what fields should I edit, what information am I missing. Why it does not work.
Thanks
Answer: Which version of Magento did you used ? If it's 1.9.1 - it's using queue & cronjob to send email. You need to setup cronjob correctly.
Comment: Its Magento ver. 22.214.171.124 . Not sure if I fixed it, I created email in Hostgator with @mywebsitename.com and added to configurations, can you tell me about Cronjob, where should I configure it? And what it does? I sent email to myself and it went to spam folder, I marked it as normal. and went in inbox, not sure if all my customers receive it in spam. how can I make sure it does not go in spam.


Why the indefinite article is used with a proper name?

Question: Reading Dune by Frank Herbert, I came across a sentence – That drunken fool of an Idaho!
I know that this type of expression is usually used to render rebuke, scorn, contempt and what not. But I am not sure why the indefinite article is used here. It seems misplaced to me, because semantic of the phrase implies that there is only one man called Idaho who deserves that much of irritation, and there is no meaning of idaho-type men in it.
While making my question, I came upon this answer on the site. According to it, the indefinite article is used idiomatically to suggest that a person in question has some characteristic quality applicable to all the likes. That is, all Idahoes, due to some intrinsic personal traits, are utter fools when drunk. Is it true in the case of the sentence?
Comment: I immediately thought of Gandalf in 'The Lord of the Rings' calling Pippin [Fool of a Took](https://www.answers.com/Q/What_is_a_%27fool_of_a_took%27). I wasn't aware before looking this up that the phrase has become commonly used since the films came out, but I'm not sure that I agree with the theory that Gandalf meant to imply that all the Took family were foolish. Compare [this](https://www.merriam-webster.com/dictionary/fool%20of%20a).  I think it's just an idiomatic way of saying 'that foolish Idaho', and the article doesn't serve any logical purpose.
Comment: We also use a/the to highlight one side/set of characteristics of a person. "Don't wait, only to become hungry and give in to your cravings--that's what *the* old Sarah would do. We want *a* new Sarah--one who schedules healthy snacks to get from one meal to the next."
Comment: Isn't 'Idahoan' more commonly used?
Answer: Merriam-Webster lists 'fool of a' as an idiom. I'd agree ... the grammar, including the use of the article, being odd in this fixed expression. The meaning would be reasonably clear to someone meeting it for the first time. It's a snowclone, with various nouns including surnames and other class-specifying proper nouns.
There must be some denigration, if only by association, of the set mentioned, but this varies to quite an extent (brother of yours ... politician?) But I'd say that there is no great emphasis on the class the person being tongue-lashed belongs to: the class is added as an identifier ('brother of yours') and/or to add substance to the censure ("Fool!" is sufficient, but "Fool of a Took!" is memorable).

fool of a [idiom] [informal]
— used to describe a person as foolish

Only that fool of a brother of yours would ask such a silly question!

Fool of a Took! [Tolkien, Gandalf, via Kate]
some fool of a civil servant [Free Dictionary]
That Fool of a Priest [Philip Rush]
Oh , that fool of a barber .... [Martial; Philogelos]
If that fool of a Roman wanted her .... Simon Young; Farewell Britannia ...]
Comment: So, the emphatic expression intertwined with idiom – that's what it is. Thanks all of you!


How to save transparent and originals colors of images in render?

Question: In blender i chose 'color management' - standard. I used Eevee
Then added "images as planes". Images have transparent parts, so i used principled BSDF with alpha. But in the render, images didn't match colors as original images. Also images change the color if i change world color. I can use just image texture without principled BSDF (colors match colors of original images), but transparent part turn into black color.
How to save transparent and originals colors without using white world color and transparent background in render properties?
Answer: if you don't want the world to influence the color, you can plug the image into the Emission input of the Principled BSDF:


Mann Whitney test

Question: I have data of 2 groups: 150 vs 70. Can I perform Mann Whitney test as my data was not normally distributed. Should the sample size of two groups be the same in order to run Mann Whitney test ?
Comment: There's too little information here to judge suitability of Mann-Whitney. Note that it doesn't test the same hypothesis as a t-test (without additional assumptions) but you don't even mention what hypothesis you want to test, nor anything about your variables, nor your sampling. Maybe your variables are 0/1 (in which case I'd suggest something else). Maybe you're comparing a multiset with a subset of it, which would make Mann-Whitney unsuitable as-is. You could be comparing convenience samples. It would be quite irresponsible to jump in with a yes or no on the basis of so little information.
Comment: (The question on whether you need the same sample size can be answered by looking at any set of tables for the test. Googling *Mann-Whitney tables* gets dozens of examples, which all show entries for different sample sizes - like [here](http://ocw.umb.edu/psychology/psych-270/other-materials/RelativeResourceManager.pdf) for example - but I imagine you have some already)
Answer: Yes. You can use the Mann-Whitney U test for two samples with unequal sample size. However, the statistical power might be limited although it shouldn't matter for you because your sample size is large enough.
Mann-Whitney U test with unequal sample sizes

Mann Whitney test


Removing padding from features extracted from pre-trained VGG16 using PyTorch

Question: I'm using a pre-trained vgg16 as the backbone for a U-Net segmentation model. The code i have is working
fine, but I was wondering if there is a way of removing the padding from the feature layers?
In the source code for the pre-trained vgg16 model it seems that the padding is set to 1 https://pytorch.org/docs/stable/_modules/torchvision/models/vgg.html#vgg16 . So i would like to know if there is a way of altering this after importing the pretrained model?
For example in the code:
<code>import torchvision.models as models

vgg16 = models.vgg16()
conv1 = vgg16.features[0]

print(conv1)

Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
</code>
I would like to remove the padding, to reduce the effect of artifacts at the edges.
Thanks in advance for any advice.
Answer:
I'm using a pre-trained vgg16 as the backbone for a U-Net segmentation model. The code i have is working fine, but I was wondering if there is a way of removing the padding from the feature layers?

If you change the structure (remove the padding) of the pretrained model layer (parameter) you can say "goodbye" to pretrained model.


What is the main requirement for two arbitrary quantum states to be able to serve as qubit states?

Question: Does it need to be orthogonal ?
If now the state is not arbitrary but a coherent state $\lvert\alpha\rangle$, if we use $\lvert0\rangle=\lvert\alpha\rangle$ and $\lvert1\rangle=\lvert-\alpha\rangle$, what condition on the value of $\alpha$ does this requirement set for our qubit coding?
Comment: There is no standard interpretation for the symbol used inside a ket, it is just some label. It does not even necessarily represent a number. (for example we often write $|\psi\rangle$ to mean "the state with wavefunction $\psi(x)$") Consequently asking "what are the conditions on $\alpha$" does not really make sense.
Comment: Thank you for your answer, but by $\alpha$ I meant coherent states, here used for continuous variables coding. I'll edit my question.
Answer: Quantum computing with continuous variables is a full field in itself, with many different paradigms for how to actually do the information processing. Therefore, there is not necessarily a single straightforward answer to your question as this depends on what paradigm you're using, how you plan to physically implement this paradigm (i.e. what sort of errors are you expecting), and how you plan to do error-correction. For a reasonable review of part of this field, see Ref [1]. Generally, however, you aren't limited by what values of $\alpha$ you choose to use so much as other factors such as how well you can entangle and how you do your error correction (which includes factors like sources of noise etc).
However, there is a proposal to use coherent states in exactly the way you mention as the computational qubits (Ref [2]). They restrict their values of $\alpha \ge 2,$ utilizing the fact that this makes the overlap of the two states roughly orthogonal as $\left|\langle\alpha|-\alpha\rangle\right|^2\le 1.1\times 10^{-7}$ for $|\alpha|\ge 2$. However, this is not a strict requirement (as pointed out in the paper) as one can modify their scheme to use $|0\rangle = |\alpha\rangle + |-\alpha\rangle$ and $|1\rangle = |\alpha\rangle - |-\alpha\rangle$ as an exactly orthogonal bases (with no limit on the values $\alpha$ can take).
References

C Weedbrook, S Pirandola, R García-Patrón, NJ Cerf, TC Ralph, JH Shapiro, and S Lloyd, "Gaussian quantum information," Reviews of Modern Physics 84, 621–669 (2012).
doi:10.1103/RevModPhys.84.621
arXiv:1110.3234
TC Ralph, A Gilchrist, GJ Milburn, WJ Munro, and S Glancy, "Quantum computation with optical coherent states," Physical Review A 68, (2003).
doi:10.1103/PhysRevA.68.042319
arXiv:quant-ph/0306004
Answer: It depends on what you want to do with it. In some sense yes, orthogonality is enough to have a pair of states to act as an effective qubit.
If two states are not perfectly orthogonal, that can still be fine. This is the case for the example you mentioned: a state like $|\alpha\rangle+|-\alpha\rangle$, with $\alpha$ big enough, can still be considered as an effective qubit. This is because $\langle\alpha|-\alpha\rangle=e^{-2|\alpha|^2}$, so that the overlap is negligible.
This kind of state is however usually referred to as a cat state more than as a "qubit".
It is to be noted that for many pairs of orthogonal states it is simply not of much use to think of them as a "qubit", because there is no (simple, known) way to use them as a qubit.
By this I mean that it may be highly nontrivial to perform the equivalent of single-qubit operations for such systems, or even worse to perform many-qubit operations between sets of such "qubits".


Leader clustering algorithm explanation

Question: I am trying to understand this algorithm, but not able to get proper documents and explanations. Can someone please help me understand this clustering algorithm.
Comment: Kindly post if you found any reference
Comment: Yes, i have found one. Will post. Please give me a day or two.
Comment: H. Spath, Cluster Analysis -- Algorithms for Data Reduction and Classification of Objects, Ellis Horwood Limited, West Sussex, UK, 1980.
Answer: Posting the answer so that it is helpful to others.
Leader algorithm is a incremental clustering algorithm generally used to cluster large data sets. This algorithm is order dependent and may form different clusters based on the order the data set is provided to the algorithm. The algorithm consists of the following steps.
Step 1: Assign the first data item, P1 to cluster C1. This data set will be the leader of the cluster C1.
Step 2:Now move to the next data item say P2 and calculate its distance from the leader P1. If the distance between P2 and leader P1 is less than a user specified threshold (t) then data point P2 is assigned to this cluster (Cluster C1). If the distance between leader P1 and data item P2 is more than the user specified threshold t, then form a new cluster C2 and assign P2 to this new cluster. P2 will be the leader of the cluster C2.
Step3: For all the remaining data items the distance between the data point and the leader of the clusters is calculated.  If the distance between the data items and the any of the leader is less then the user specified threshold, the data point is assigned to that cluster.   However, If the distance between the data point and the any of the cluster's leader is more than the user specified threshold, a new cluster is created and that particular data  point is assigned to that cluster and considered the leader of the cluster.
Step 4: Repeat Step 3 till all the data items are assigned to clusters.
Example to get the theory clear.
Consider the patterns are located at
A (1, 1),B(1, 2), C(2, 2), D(6, 2), E(7, 2), F(6, 6), G(7, 6)

Let the data be processed in the order A, B, C, D, E, F and G, and the user specified threshold T be 3.
A(1, 1) is the first data item processed and it is assigned to cluster C1 and also made the leader of C1.
For the second point B, its distance from the leader A is calculated.
Using euclidean distance formula ( Distance(a, b)) = √(x - a)² + (y - b)² ), we get the distance as √(1 - 1)² + (1 - 2)² = 1, this is less than the user specified threshold 3, so B is assigned to the Cluster 1.
For the third point C(2, 2) the distance  between leader A(1, 1) of cluster C1  and point C is calculated. Using the Euclidean formula the distance is √(1 - 2)² + (1 - 2)² = 1.41, which is less than
threshold, so C is also assigned to C1.
Distance between A and D (√(1 - 6)² + (1 - 2)² = 5.099 ) is more than the user specified threshold 3, so a new cluster is created and D is assigned to cluster C2. D is the leader of this cluster.
For the point E, its distance from A (leader of C1 ) and D (leader of C2) is calculated. Since Distance(D,E) is less then the user specified threshold 3, it is assigned to cluster 2.
The distance of F from A (the leader of C1) is 7.07 and from D (the leader of C2) is 4.
Both these distances are above the threshold and therefore F is put into the new cluster C3 and is made the leader of this cluster.
For G the Distance(A,G), Distance(D,G) and Distance(F,G) are 7.81, 6.41 and 1 respectively. Since Distance(F,G) is less then user specified 3 it is assigned to cluster 3.
It can be seen that if the data had been processed in a different order, the cluster
leaders would have been different—even the clusters can vary. If C occurred before
A and B, then C would have been the leader of C1. If D occurred before and the
distance between C and D was less than the threshold, it would have been in C1. This
may not occur if A is the leader. The leader algorithm is therefore order dependent and may give different results based on the order of processing.
Comment: The algorithm has excellent implementation in R:
leaderCluster in CRAN.
Does anyone know a Python implementation?
scipy.cluster.hierarchy.leaders is NOT the leader-algorithm! It is a different one
Comment: Even if I specify radius =say 1km. I am getting points which are say 10 kms from the centroid. Why is the algorithm enforcing this radius constraint strictly? Is there a way to strictly enforce the radius constrain?
Comment: Any additional comments on the performance and accuracy aspect of it. I understand it is reasonably faster than K-means as there is no optimization part involved. But how effective is it in classifying the dataset into clusters

Leader clustering algorithm explanation


Importance of variables in RandomForest in R

Question: I'm using varImpPlot() to evaluate the importance of variables from my rf model, and I can't decide wich variable I have to delete from my model. I'm not sure about the diference between "MeanDecreaseAccuracy" and "MeanDecreaseGini", I guess the last one can measure the purity of the tree nodes, but as an example of my model: I have a variable that has a MeanDecreaseGini of about 100 and at the same time a MeanDecreaseAccuracy of about zero.! Because of this I can't decide if this variable is good or bad.
Comment: Can you add a visualization to this question highlighting the points? This may help others understand your situation. You can use rattle package as well. It contains random forest.
Answer: If the features scale of measurement and/or number of categories vary, permutation accuracy is more reliable than the GINI index (Strob et al. 2007).
However, better yet is to use Boruta all relevant variable selection prior to running random forests to determine which variables are relevant to the target property, and which are not. This allows you to trim your dataset to only useful, or relevant variables.
Strobl, Carolin, Anne-Laure Boulesteix, Achim Zeileis, and Torsten Hothorn. "Bias in Random Forest Variable Importance Measures: Illustrations, Sources and a Solution." BMC Bioinformatics 8 (2007): 25. doi:10.1186/1471-2105-8-25.


Is the following case about jury nullification true?

Question: Let's say that someone lied about jury nullification in order to get on a jury with the intent to nullify, and they then get indicted for perjury. If they just demanded a trial by jury, would the facts of their case require that their jury learn about jury nullification? If so, would all they have to do is convince them that this whole case is absurd, in order to be found not guilty of nullification due to their own jury nullifying the charges?
Comment: *"all you have to do is convince them that this whole case is absurd and you'll probably be found not guilty"* is the case for any trial
Answer: The theory of jury nullification would likely be relevant to the case, and the defendant would likely be entitled to give the jury at least some explanation of what it is and how it works.
I think you could expect the court to take extra measures to ensure that the jury was screened for openness to nullification, and to really hammer on that message in the jury instructions, which would likely provide additional detail to the jury about how and why nullification is illegal.
If the defendant could, despite all that, convince the jury that the case is absurd, nullification would be just as much an option in the second case as in the first.
Answer: I very much doubt that a perjury case would be brought against a juror in these circumstances.
Perjury cases resulting from court trials are vanishingly rare, and perjury cases resulting from a juror's statement about their intentions rather than about a specific presently existing fact are even more rare.
Proof of the case would almost surely rest on evidence regarding what actually happened in the deliberations of the jury and that would be inadmissible evidence because they are deliberations (absent a motion to set aside a verdict due to racial discrimination). So, there would really be no way to prove that case.
It might very well be dismissed in a preliminary hearing or in motion practice prior to trial.
Comment: @Someone Possibly. There are no cases on point. The decision allowing this in a case of racial discrimination is very new and its full implications haven't been established.
Comment: Is racial discrimination the only type of discrimination that allows for this? Could there be, for example, a motion to set aside a verdict due to gender discrimination?