[1] Find a linear (O(n) in time) algorithm which does in-place
riffle shuffle of an array of size 2n.
[2] Write a program to check for balanced brackets (and braces, and parentheses)
without using a stack.
"{[]()" false.
"{[]()}" true.
")))(((" false
"((()))" true
"{}([]())" true
"[(]){}" false
Use O(n) time and O(1) space.
Amazon
Saturday, February 2, 2008
Algorithm interview questions
Posted by
innersmile
at
8:59 PM
0
comments
Wednesday, January 30, 2008
A probabalility question
then painting the first ball to match the second. What is the expected
number of drawings before all balls are the same color?
Posted by
innersmile
at
10:27 PM
0
comments
Labels: brain teaser, expectation, probability, puzzle
Saturday, January 19, 2008
from MATLAB to Python/NumPy
Recently I started to translate the
MATLAB and Octave Functions for Computer Vision and Image Processing.
by Peter Kovesi into a Python package.
See
http://cvgmi.googlecode.com/files/fundamental_matrix.py
Posted by
innersmile
at
8:50 PM
0
comments
Labels: computer vision, MATLAB, python
Tuesday, January 15, 2008
Python tips and tricks
Q: How to add current path into system?
A: sys.path.append(os.path.abspath('./'))
Posted by
innersmile
at
8:35 PM
0
comments
Labels: python
Sunday, December 9, 2007
MATLAB tips and tricks
External Links:
[1] http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html
[2] http://www-pord.ucsd.edu/~matlab/
[3] http://www.cs.ubc.ca/~murphyk/Software/matlab_tips.html
[4] http://www.ecogito.net/matlab/
Posted by
innersmile
at
2:11 PM
0
comments
Labels: MATLAB
Saturday, December 8, 2007
MATLAB Mex File for Const Time Median Filtering
Step1:
Download the C code from http://nomis80.org/ctmf.html
Step2:
Write the Mex function below, for example, with
name ctmf_mex.c
Step3:
In Matlab, run "mex ctmf_mex.c ctmf.c -output ctmf"
#include "ctmf.h"
/*
void ctmf(
const unsigned char* const src, unsigned char* const dst,
const int width, const int height,
const int src_step, const int dst_step,
const int r, const int cn, const long unsigned int memsize
);
*/
#include "mex.h"
#include "matrix.h"
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
unsigned char *I0, *I;
int height, width, r;
mwSize dims[2];
/* Check for proper number of arguments */
if (nrhs != 2) {
mexErrMsgTxt("Two input arguments required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
}
I0 = (unsigned char*)mxGetPr(prhs[0]);
/* Check the dimensions of Y. Y can be 4 X 1 or 1 X 4. */
height = mxGetM(prhs[0]);
width = mxGetN(prhs[0]);
r = (int)mxGetScalar(prhs[1]);
if (!mxIsClass(prhs[0],"uint8")) {
mexErrMsgTxt("I0 has be a matrix of type uint8.");
}
dims[0] = height;
dims[1] = width;
/* Create a matrix for the return argument */
plhs[0] = mxCreateNumericArray(2, dims, mxUINT8_CLASS, 0);
I = (unsigned char*)mxGetPr(plhs[0]);
ctmf(I0, I, height, width,
height, height,
r, 1, 512*1024
);
}
Posted by
innersmile
at
10:35 PM
0
comments
Labels: image processing, MATLAB, programming
magic commands in iPython
from IPython.iplib import InteractiveShell
#magic function about
def magic_about(self,parameter_s=''):
"""Equivalent to ... """
print "hello world"
InteractiveShell.magic_about = magic_about
del magic_about
http://pages.physics.cornell.edu/~myers/teaching/ComputationalMethods/python/ipython.html
http://ipython.scipy.org/moin/IpythonExtensionApi
Posted by
innersmile
at
11:04 AM
0
comments