- 博客(40)
- 资源 (1)
- 收藏
- 关注
原创 Find the kth largest element in an unsorted array
This is should be an old problem, I had written some code long time ago. This time I just write some code for review. The idea is the same as quick sort. There are many other methods too, but this met
2016-03-11 22:30:00
719
原创 Hide an Image in Another Image
For one assignment of web programming, there is some requirement like below for hiding images, the idea idea is important to remember.So I paste the code I written before for the record.Requir
2015-12-09 15:10:05
646
原创 Document distance note
Document DistanceDocument = sequence of words-Ignore punctuation & formattingWord = sequence of alphanumeric charactersHow to define "distance"?Idea: focus on shared wordsWord
2015-09-15 18:17:43
898
原创 Peak Finding
1D Peak FindingObjectiveGiven an array A with n elements, find the index i of the peak element A[i] where A[i] >= A[i - 1]and A[i] >= A[i + 1]. For elements on the boundaries of the array, the
2015-09-15 18:12:24
1867
原创 PageRank Spark implementation
As you know, PageRank is very famous algorithm. For the detail of pagerank defination and implemenation, you can refer tohttps://en.wikipedia.org/wiki/PageRank There are many implementa
2015-09-07 18:51:01
1019
原创 Select Sort in scala
Below I written a simple select sort in scala, just for record something.object SelectSort { /* Return the index of the minimum element in the given array, index range [left, right]
2015-08-17 18:57:41
586
原创 Logical Indexing in matlab
As you know, vectorized programming has many advantage places. It's neat, effienct, sometimes it is very short and much easier than writing long tedious loops code. When manipulate matrix or data, i
2015-05-08 11:05:24
1674
原创 A matrix cheatsheet between matlab and numpy
Note: in order to use "numpy" as "np" as shown in the table, you need to import NumPy like this:import numpy as np MATLAB/OctaveNumPyCreating Matrices (here: 3x3 mat
2014-12-03 13:16:06
1245
原创 Lowest common ancestor in binary search tree
This is a very common question
2014-09-01 16:20:40
520
原创 k Means clustering c++ implementation
KMeans is very common unsupervised learning algorithms, below is the algorithm.c++ implementation:#include #include #include #include #include using namespace std;// get the all the li
2014-01-03 18:25:02
1578
原创 Merge Sort and apply it to an interview question
Merge Sort is very efficient in sorting a list of elements with O(nlgn) complexity. It is used with divide and conquer strategy.A few days ago, I came to an interview question, the description o
2013-08-17 10:38:48
906
原创 Implement a spell checker with java
When you typing a word, many systems will suggest many words for you to select the word which you intend to type. This is spell checker.It will calculate the edit distance between a dictionary. Ever
2013-05-04 16:54:07
879
原创 Longest common subsequence problem and poj 1159 Palindrome
The longest common subsequence problem is a very basic problem in dynamic programming. If you dive in,there is manyothermethods to compute thelongest common subsequence. Hereis just the very basic
2013-04-24 12:40:18
787
原创 Parallel array summation
C++ code:#include #include #include #define NUM_THREADS 4int N;int *X;int gSum[NUM_THREADS];//pthread_mutex_t sum_mutex = PTHREAD_MUTEX_INITIALIZER;// do sumvoid *summation(void *p
2013-02-13 21:45:49
528
原创 How to install tomcat on linux
1. Downloadtomcat 7 from apache's website. My downloaded package isapache-tomcat-7.0.32.tar.gz 2. Extract thepackage to /usr/share directory. # tar xzvf apache-tomcat-7.0.32.tar.gz
2013-02-13 14:46:29
1581
原创 How to install eclipse on linux
1. Downloadeclipse tar package. Download eclipse juno from eclipse's homepage to a folder. 2. Extract the tar package to /opt folder. # tar -xvzf eclipse-jee-juno-SR1-linux-gtk.tar.gz -C
2013-02-13 14:35:08
867
原创 How to install jdk 1.7 on Linux
1. Download jdk-7-linux-i586.tar.gz from Oracle'swebsite. 2. Extract tar package. cd to the directory the tar package is downloaded.# sudo tar xzvfjdk-7-linux-i586.tar.gz the extra
2013-02-13 14:10:00
732
原创 How to config Eclipse CDT with pthread
When compiling multithread programs in eclipse cdt, the pthread library should be configured, it is easy way. For C project.1. Project -> Properties -> C/C++ Build -> Settings -> Tool Settings ->
2013-01-13 10:52:22
1408
原创 QuickSort two way, three way partition and many other implementations
Quicksort is so famous which was honored as one of the top 10 algorithms of 20th century in science and engineer. It is use thedivide and conquer strategy. Divde the array into two subarray and recu
2013-01-08 15:19:26
3607
原创 Missionaries and Cannibals problem breadth first search implementation
Problem description: Three missionaries and cannibals want to cross the river using a boat which can carry at most two people, under the constraint that, for both banks, if there are missionries p
2012-12-15 13:56:43
4482
原创 Simple T9 implementation with Trie
package hello.test;import java.io.*;import java.util.LinkedList;import java.util.Queue;public class Trie { private final int R = 26; // the trie branches private Node root = new N
2012-12-07 11:03:53
3157
1
原创 Disjoint set and poj 1611
package hello.test;import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;public class DisjointSet { private final static int DEFAULT_SIZE = 10; private in
2012-11-30 17:20:56
706
原创 Incomplete checkerboard covering
Cover a checkerboard that has one corner square missing. The size of the board is usuall 2**k, use recursive way the board will bedivided into four 2**(k-1) size small board. Cover the center board
2012-11-28 15:07:35
665
原创 Sudoku backtracking with one dimension array
package hello.test;import java.io.*;import java.util.*;public class Sudoku { private static final int N = 9; // the size of the board private int[] board; // the one dimension array
2012-11-27 14:47:00
787
原创 Levenshtein's eidit distance
From Wiki, the definition of Levenshtein distance is astring metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is equal to the numb
2012-11-24 12:06:16
562
原创 A simple bouncing ball
from graphics import *class BouncingBall(): def __init__(self, win,center, ball_radius, x, y): self.ball_circle = Circle(center, ball_radius) self.win = win self.
2012-11-22 15:33:12
1391
原创 Quick sort and the Kth number
import random# partition list L use the rightest element as pivot def partition(L, left, right): x = L[right] i = left - 1 for j in range(left, right): if L[j] < x:
2012-11-22 15:02:00
582
原创 Reverse linked list using stack and stack's implementation
class ListStack: # create an empty stack def __init__(self): self.elems = list() def isEmpty(self): return len(self) == 0 # return the number in the stack
2012-11-20 17:35:02
483
原创 Circular linked list and Josephus ring
class ListNode: def __init__(self, data): self.data = data self.next = None class CircleList: def __init__(self): self.head = None # add a no
2012-11-20 09:59:30
720
原创 N queen problem implementation in python
class NQueen: def __init__(self, n): self.n = n self.board = self.create_borad(self.n) self.queens = 0 self.row_exist = [0 for i in range(n)] # row check queen exis
2012-11-19 18:08:42
795
原创 Computing PI using Monte Carlo method
import mathimport randomclass Point(): def __init__(self, x = 0, y = 0): self.x = x self.y = y def set_rand_range(self, rand_start, rand_end): self.rand_st
2012-11-19 15:14:35
525
原创 Creating a Windows 2008 Server or Win7 without 100 MB System Reserved Partition
1.Once Windows 7 Setup is loaded, press Shirt + F10 keys at the first setup screen (which allows selection of language, keyboard and locale). A Command Prompt window will be opened.2.Run D
2012-11-15 11:09:26
581
原创 Dynamic Array Implementation in Java
package test.dynamic.array; import java.util.*; public class DynamicArray { private static final int INIT_SIZE = 1; private T[] array; // the internal array private int size = 0
2012-11-15 11:03:40
845
原创 Simple base conversion implementation use java
The stack interface defination:package test.baseconversion;public interface IStack { public abstract void push(T value); public abstract T pop(); public abstract T top(); public
2012-11-15 11:00:02
436
原创 How to Configure Eclipse for Python
Python3 must be installed before the complete instillation can be completed. If you don't have Python installed you can install it usingthese directionsInstall the PyDev plug-in for Eclipse
2012-11-15 10:59:27
1188
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人