Sort Colors


Check Soduku Solution

The objective of Soduku game is to fill a \(9 \times 9\) grid with digits so that each column, each row, and each of the nine \(3 \times 3\) sub-grids that compose the grid (also called “boxes”, “blocks”, “regions”, or “sub-squares”) contains all of the digits from 1 to 9. A solved Soduku game is like:

Least Recently Used(LRU) Cache

According to LeetCode:

Binary Tree Operations(I)

This is the first article on binary tree operations. For other topics on binary tree, please refer to:

Action Recognition with Fisher Vectors

This is a summary of doing human action recognition using Fisher Vector with (Improved) Dense Trjectory Features(DTF, and STIP features( on UCF 101 dataset( In the STIP features, two low-level visual features HOG and HOF are integrated, with dimensions 72 and 90 respectively. The (improved) DTF employ more features(TR, HOG, HOF and MBHx/MBHy) with longer dimensions.

Implementing Inclusion Property with SimpleScalar

  1. Inclusion Property
  2. Code Change
  3. Experiments
  4. Conclusion

How To Install Jekyll in Mac OSX Mavericks

  1. Procedure of installing Jekyll in Mac OS X

  2. Install Xcode Command line tools:

  3. Clang error during install Jekyll

clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [redcarpet.bundle] Error 1


C++ Code to Print Pascal Triangle

Printing Pascal Triangle seems like an easy problem, however, it is not that easy to print a good-looking Pascal Triangle. 

To print the Pascal Triangle, for each line, first print spaces to the left of numbers, and then print digit numbers.

To calculate Pascal numbers, two assays can be used: one array to store numbers of above line, the other array to store numbers of this line. The first line has 1 number(1), the second lien has 2 numbers(1 1), the third line has three numbers(1 2 1) and so on.

To make the Pascal Triangle more readable, print spaces between two neighbor  numbers in the same line.

// Pascal triangle
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

const int WIDTH=7;
int main()
	int* oldarr=new int[WIDTH]; // store numbers of above row
	int* newarr=new int[WIDTH]; // store numbers of current row

	for(int i=0;i<WIDTH;++i) // cntrol row counting
		for(int j=0;j<WIDTH-i-1;++j) // left space
			cout<<setw(2)<<" ";

		// set default boundary numbers

			for(int k=1;k<i;++k)

		// Print the middle part
		int idx=0;
		int flag=(WIDTH-i-1)%2;
		for(int j=WIDTH-i-1;j<WIDTH+i;++j)
			} else {
				cout<<setw(2)<<" ";
		//for(int j=WIDTH+i;j<WIDTH;++j) // Print right space, if you like
		//	cout<<setw(4)<<" ";


	delete [] oldarr;
	delete [] newarr;

	return 0;

The output looks like:

           1   1
         1   2   1
       1   3   3   1
     1   4   6   4   1
   1   5  10  10   5   1
 1   6  15  20  15   6   1

BACI Simple Install and Compile Guide

This is a guideline for a course of this semester, for which I am serving as a teaching assistant. I publish it here in hope that it can also help someone else who want to use BACI.

Install BACI

  1. Go to and download BACI executables:

  2. For windows user, after download and unzip the BACI DOS executables, please put the folder called badosxe directly under the C:\ drive so it’s easy to find it. You can do all your BACI work inside this directory.

    • If your badosxe folder is C:\badosxe, then in your command prompt (cmd) your path should be C:\badosxe> bacc <file_name> .

  3. For Linux user, after download and gunzip the BACI executables, please make sure to add balnxxe into your PATH: export PATH=$PATH:/path/to/your/balnxxe (You also can add this line into $HOME/.profile, so that this command will be executed every time you login).

  4. If you want to use jBACI(BACI with a graphical IDE), please go to, and choose the Unfortunately, currently jBACI is only available for Windows.

  5. If you want to use BACI on the Eustis server, please download Linux version BACI first, gunzip it and then upload them into your home folder of Eustis server. Please remember to add BACI executables into your PATH(as step 3).

  6. NetBeans + BACI plugin is the best choice for people who prefer a modern IDE or MAC users. You need to install NetBeans first, and then follow the guide of setting up BaciBeans. NetBeans is a cross-platform IDE, so it can work on all operating systems that have Java JDK installed.

Compile and run BACI program

  1. Make sure that bacc is in your PATH, or put your BACI program in the same folder of bacc. Note the .cm extension. This is the extension that identifies BACI source files to the BACI compiler.

  2. Invoke the compile command bacc This creates an object file called your_prog.pco and also a listing file called your_prog.lst.

  3. Invoke the interpreter through the command bainterp your_prog (please note, there is no suffix here) to execute your code. bainterp has an option -t that will display the order in which processes terminate within the program.

Verify the installation of BACI

  1. Download

  2. Run command  bacc If you see following outputs, then the is successfully compiled:

bo@HEC-2GQFTK1:~/Documents/BACI$ bacc

Pcode and tables are stored in example.pco

Compilation listing is stored in example.lst

  1. Execute command  bainterp -t example. If you get following message, then bainterp runs correctly.

bo@HEC-2GQFTK1:~/Documents/BACI$ bainterp -t example

Source file:  Wed Jan 22 15:16:12 2014

Executing PCODE ...

before v(count) value of count is 0

process 2 increment,  procedure increment ended

before p(count) value of count is 1

process 1 decrement,  procedure decrement ended

More Options of BACI Compiler

A BACI source file using the C-- compiler should use a .cm suffix. To execute a program in BACI, there are two steps:

1. Compile a ".cm" file to obtain a PCODE file (.pco)

Usage: bacc [optional_flags] source_filename


-h show this help

-c make a .pob object file for subsequent linkingInterpret a PCODE file (.pco) to execute the program

2. Usage bainterp [optional_flags] pcode_filename


-d enter the debugger, single step, set breakpoints

-e show the activation record (AR) on entry to each process

-x show the AR on exit from each process

-t announce process termination

-h show this help

-p show PCODE instructions as they are executed

There is a shell script, baccint, that will call the compiler and then call the interpreter for you. It passes the options that you give it along to the interpreter. If you are using the Pascal compiler syntax, then the source file should be with a .pm suffix, and you compile the program with the bapas compiler.

Dense Trajectory Notes

Notes of Dense Trajectories

  • densely sample feature points in each frame
  • track points in the video based on optical flow.
  • compute multiple descriptors along the trajectories of feature points to capture shape, appearance and motion information.
  • Dense Sampling

    • Sampling step size \( W=5 \) pixels
    • # spatial scales ≤ 8
    • Spatial scale increase: \( 1 / \sqrt{2} \)
    • Removing points in homogeneous areas: $$ T=0.001 \times \max_{i \in l}\min(\lambda_{i}^{1},\lambda_{i}^{2}) $$, where \( (\lambda_{i}^{1},\lambda_{i}^{2}) \) are eigenvalues of point \(i\) in image \(I\) (the auto-correlation matrix).
  • Descriptors

    • Trajectory shape descriptor(TR):

where L is the length of trajectory, and the displacement vectors

  • HOG – static appearance information
  • HOF – local motion information
  • MBH – motion descriptor for trajectories
  • Format of DTF features

The format of the computed features

The features are computed one by one, and each one in a single line, with the following format:

frameNum mean_x mean_y var_x var_y length scale x_pos y_pos t_pos Trajectory HOG HOF MBHx MBHy

The first 10 elements are information about the trajectory:

  • frameNum:     The trajectory ends on which frame
  • mean_x:       The mean value of the x coordinates of the trajectory
  • mean_y:       The mean value of the y coordinates of the trajectory
  • var_x:        The variance of the x coordinates of the trajectory
  • var_y:        The variance of the y coordinates of the trajectory
  • length:       The length of the trajectory
  • scale:        The trajectory is computed on which scale
  • x_pos:        The normalized x position w.r.t. the video (0~0.999), for spatio-temporal pyramid
  • y_pos:        The normalized y position w.r.t. the video (0~0.999), for spatio-temporal pyramid
  • t_pos:        The normalized t position w.r.t. the video (0~0.999), for spatio-temporal pyramid

The following element are five descriptors concatenated one by one:

  • Trajectory:    2x[trajectory length] (default 30 dimension)
  • HOG:           8x[spatial cells]x[spatial cells]x[temporal cells] (default 96 dimension)
  • HOF:           9x[spatial cells]x[spatial cells]x[temporal cells] (default 108 dimension)
  • MBHx:          8x[spatial cells]x[spatial cells]x[temporal cells] (default 96 dimension)
  • MBHy:          8x[spatial cells]x[spatial cells]x[temporal cells] (default 96 dimension)
  1. Improved Dense Trajectories

  • Explicit camera motion estimation
  • Assumption: two consecutive frames are related by a homography.
  • Match feature points between frames using SURF descriptors and dense optical flow
  • Removing inconsistent matches due to humans: use a human detector to remove matches from human regions (computation expensive)
  • Estimate a homography with RANSAC with these matches


  1. H Wang, C Schmid, Action recognition with improved trajectories, ICCV 2013
  2. H Wang, A Kläser, C Schmid, CL Liu, Dense trajectories and motion boundary descriptors for action recognition, International Journal of Computer Vision, May 2013, Volume 103, Issue 1, pp 60-79