• Interactive Poisson Blending on GPU
    Interactive Poisson Blending on GPU
  • 404 Not Found In Two Triangles
    404 Not Found In Two Triangles
  • Simplest and Fastest GLSL Edge Detection using Fwidth
    Simplest and Fastest GLSL Edge Detection using Fwidth

Tag: C++

N Queens Problem Revisit using Bit Operations

Finally, I have some time to revisit the N queens problem using bit operations. The following functions could solve 11 queens in 1 second:

So far to me, this is the most efficient algorithm for N queens. The code is mostly self-explenary. Please comment if anything cannot be understood.

 


Timer: How to Measure Execution Time in C++ 11

Timer is important for measuring speed-ups, or elapsed time for comparing different algorithms. We used to import <ctime> and measure the elapsed time with the following code:

However, the clock() function measures the CPU time, not actual time elapsed (which may be much greater), according to this StackOverFlow thread. Hence, here I share my code…


Quicksort, Mergesort, and Bucket sort in C

Quick Sort This is used in research code when built-in qsort does not satisfy the demands.

K-th element Qsort can be used to find the Kth smallest element a[k]:

Use partition to sort 0, 0, 0, 1, 1, 2, 2, 2…

  Merge Sort Linked List Version Here is the merge sort…