Sorting an array in C?

In C, you can use the built in qsort command: see: http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ To answer the second part of your question: an optimal (comparison based) sorting algorithm is one that runs with O(n log(n)) comparisons. There are several that have this property (including quick sort, merge sort, heap sort, etc.), but which one to use depends on your use … Read more

Finding all possible combinations of numbers to reach a given sum

This problem can be solved with a recursive combinations of all possible sums filtering out those that reach the target. Here is the algorithm in Python: This type of algorithms are very well explained in the following Stanford’s Abstract Programming lecture – this video is very recommendable to understand how recursion works to generate permutations of solutions. … Read more

Difference between O(n) and O(log(n)) – which is better and what exactly is O(log(n))?

It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size. Big-O notation doesn’t mean an exact equation, but rather a bound. For instance, the output of the following functions is all O(n): Because as you increase x, their outputs all increase linearly – if there’s … Read more

How are the following functions O(N^3)?

Do you know, f(n) = O(g(n)) implies f(n) <= constant* g(n), right? In other words, it means, when you plot the graph of f(n) and g(n) then after some value of, g(n) will always be more than f(n). Here g(n) is N^3 and remaining comes in f(n). Now, N^3 is always >= options a, b, c. hence answer id D ðŸ™‚ Edit: Following statements are true, n=O(n) n=O(n^2) n=O(n^3) But only n = O(n) is tight upper bound and that is what … Read more

Difference between Big-Theta and Big O notation in simple language

While trying to understand the difference between Theta and O notation I came across the following statement : But I do not understand this. The book explains it mathematically, but it’s too complex and gets really boring to read when I am really not understanding. Can anyone explain the difference between the two using simple, … Read more

Image Segmentation using Mean Shift explained

The basics first: The Mean Shift segmentation is a local homogenization technique that is very useful for damping shading or tonality differences in localized objects. An example is better than many words: Action:replaces each pixel with the mean of the pixels in a range-r neighborhood and whose value is within a distance d. The Mean … Read more