慕慕的玩具(4):疯狂对对碰背后的数学模型 Steiner System和Finite Projective Plane(上)

慕慕的玩具和游戏背后有很多有趣的算法话题。之前已经写三篇(如下):

第四篇的游戏是一组卡牌,称为疯狂对对碰,网上很容易买到,如下图:

这个游戏是由一组卡牌,每个卡牌上有一些图标(这里是不同国家的国旗),任何两张卡牌的国旗组合里,有且只有一个共同点(这是我们的游戏经验)。家人陪慕慕玩这个游戏的办法是,洗牌,然后每个人分同样多的牌,每次各出一张,最快发现唯一相同国旗的人,赢走两张牌。最后计赢取的牌的数目决定胜负。

Continue reading

Analysis of the number of swapping in partition of Quicksort

Quicksort is an elegant and efficient sorting algorithm. Analysis of quick sort is a lot of fun. The core part of quick sort algorithm is partition the original array into two parts. This part of code is shown below (in java):

private void quicksort(int[] a, int lo, int hi) {
    if (hi <= lo) return;
    int i = lo - 1, j = hi;
    int t, v = a[hi];
    while (true) {
        while (a[++i] < v);
        while (v < a[--j])
            if (j == lo) break;
        if (i >= j) break;
        t = a[i]; a[i] = a[j]; a[j] = t;
    }
    t = a[i];
    a[i] = a[hi];
    a[hi] = t;
    quicksort(a, lo, i - 1);
    quicksort(a, i + 1, hi);
}
Continue reading

On dynamic hash expansion

Dynamic hash table will expand when it is full. If we simply use modulo to map hash value to the entry position, there are some properties on the data movement while expanding.

Let’s start with some questions:

  1. If at the very first, the table size is n, and for the entry at ith place ( k \mod n = i), what is the possible place for it after expanding?
  2. Can we describe the moving process?
Continue reading

Coupon collector’s problem:An infinite-series perspective

Background

If you are not familiar with Coupon collector’s problem, please first read the following page:

Six years ago when I was in graduate school, I encountered this problem. I did not want to use Indicator variable method to solve it, so I tried my best to solve it using infinite series. I came up with a complicated formula which was not accurate and I am not satisfied because this means it is wrong.

the wrong formula of six years ago
Continue reading