Posts tagged with: C programming

Some inefficient algorithms you don't need to know!

Here we have some stupidly clever algorithms that are faster in execution but slower in convergence to solution.

First candidate to introduce you is Bogo Sort. Its idea is simpler. Shuffle the numbers until it finds the correct order. Complexity of the algorithm can be approximated as O(n.n!) (efficient hah ?). Its pseudo code can be written as;

while not isInOrder(deck):

Next one is known as Stooge Sort. The idea is to sort the initial 2/3 part t Continue Reading


What is "long long" type in c++?

long long is not the same as long (although they can have the same size, e.g. in most 64-bit POSIX system). It is just guaranteed that a long long is at least as long as a long. In most platforms, a long long represents a 64-bit signed integer type.

You could use long long to store the 8-byte value safely in most conventional platforms, but it's better to use int64_t/int_least64_t from <stdint.h>/<cstdint> to clarify that you want an integer type having ≥64-bit.