Big-O for Eight Year Olds? [duplicate]

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.

Leave a Comment