Welcome, this is Dr. Cu.

Lonely in the Dessert.

About Sorting

For small arrays, the next three classic sorting algorithm suffice.

Selection Sort

The complexity does not depend on the initial placement of the data. It's quite appropriate only for small n as O(n^2) grows rapidly. In contrast of a O(n^2) comparisons, it requires only O(n) data moves. Thus, selection sort could be a good choice over other counterparts when data moves are costly but comparisons are not.

Bubble Sort

 The number of loops depends on the initial placement of the data, which means the sorting will be terminated when no exchages are done during one pass.

Insertion Sort

The insertion sort algorithm is O(n^2) in the worst case. For small arrays, the simplicity makes it an appropriate choice. For large arrays, insertion sort can be prohibitively inefficient unless the array is already sorted, in which case, the sort is O(n).

For extremely large arrays, faster sorting algorithms are needed.

Merge Sort

As one of the two most important devide-and-conquer sorting algorithm, merge sort works in elegant recursive manners. Besides, it’s also readily extended to external sorting. Oblivious to initial placement of data, merge sort always gives the same performance. The complexity is O(nlogn), which is significantly faster than O(n^2). Despite extremely efficient with respect to time, the merge sort requires an auxiliary array. This extra storage and the necessary copying are disadvantages.

Quick Sort

Similar to Merge Sort, Quick Sort performs better when the array can be halved for each round. Thus, the complexity is O(nlog(n)), which is the best case. For the worst case, the complexity is O(n^2). The average behaviour of Quick Sort is O(nlog(n)) as well. We have shown that the  Merge Sort  is alwasy O(nlog(n)), the  Quick Sort is faster in practice and doesn’t require an auxillary array for merging.

If the data is sufficiently “random”, Quick Sort performs no worse than any known comparison-based sorting algorithms. While the worst-case behaviour of Merge Sort is of the same order of magnitude as a quick sort’s average-case behaviour, in most situations Quick Sort will run definitely faster than Merge Sort. However, the Quick Sort is significantly slower than the Merge Sort for worst case.

About Thread-safe in Java

If all the following rules are obeyed, the class is known to be thread-safe.

All fully synchonized class is a class that meets all of these conditions:

  • All fields are always initialized to a consistent state in every constructor.
  • There are no public fields.
  • Object instances are guaranteed to be consistent after returning from any non private method (assuming the state was consistent when the method was called)
  • All the methods provably terminate in bounded time.
  • All methods are synchronized.
  • There is no calling of another instance’s methods while in an inconsistent state.
  • there is no calling of any non-private method while in an inconsistent state.

Hiking Under the Beautiful Sunshine

It’s a beautiful day with great sunshines. As usual, we went outside. This weekend, we went to the Peak, nearest to our home. Some photos can be seen here.

Leaf sleeping in the sunLeaf sleeping in the sun

My First Step to the No-return Journey of Photography

Okey…this is gonna be my first shooting with my new 5d mark iii, also my first step to the no-return journey of photography. I want to thank all my friends patiently giving me precious advices on lenses choices. Finally, I gave up the in-kit 24-105mm and grabbed the bloody expensive lenses, 24-70mm f2.8 ii. By bloody, I mean abso-fucking-lutely bloody hell expensive for a green hand like me.

I can see I will definitely keep my retina Macbook Pro non-upgraded for a long time, until the TRUE next generation Mac with a brand new design.

Why don’t you have a look at my virgin shot to my billingham bag, which is also bloody ~~~ (omitted…). Yes, I know it’s a fantastic shot, and won’t allow you to comment.

My first step to the no-return journeyMy first step to the no-return journey

Though very tired today, my wife became the first model before my camera tonight. Pictures were taken around Saiwan, where we live. The album is here.

More fantastic photos are comming, stay tuned…

Nanjing Trip Day 1

师弟去南京追逐梦想,回北京顺路去趟南京。对南京的记忆相当模糊,记得当年年幼只依稀记得长江大桥。也希望借此能把记忆的空白补上一补。师弟信誓旦旦地招呼我,说他住在南京航空航天大学边上。我一查地图特别高兴,位置真好。后来发现这厮把“江宁校区”省略了。飞机降落南京禄口机场,gps显示距离南京市还30km,就这样坐了十几分钟大巴在一个偏僻小地方下了车,后来听说原来江宁区不属于南京,只是后来并了进去。不过也不算特别远,十几公里的路程,也就相当于我当年每天从酒仙桥到清华的距离。毕竟师弟来这里创业,去个花花世界也不是个事。

师弟领着个90后小朋友给我接风,去了湖南路上的南京大排档,南京菜偏甜,吃得不是特别习惯,但是个别菜很好吃。尤其发现南京的臭豆腐超出北京好几条街,所以在南京这几天,臭豆腐几乎成了必点之菜。

南京大牌档南京大牌档

南京大牌档1南京大牌档1

南京大牌档2南京大牌档2

南京大牌档3南京大牌档3

吃饱喝足玄武湖边遛了遛,太黑。倒是路边的法国梧桐树挺不错的,前段大量迫害梧桐树的运动挺操蛋的,全国各地就知道拆拆拆,什么时候这种断子绝孙的工程少了才是万幸。

法国梧桐树法国梧桐树

路过了鸡鸣寺,顿时想起当年历史课本里陈后主井里藏妃的故事,决定明天来悼念。我这个人特别不喜欢教条式的历史,但是和女人有关的题材例外。

鸡鸣寺门口鸡鸣寺门口

回去晚上仨人找个串店吃个夜宵,发现南京的啤酒真心难喝,串也不是特别敢恭维。可以理解,让温婉的江南厨子走豪放路线多少难为了。我这个人很随性,喜欢背上包就走,没有目的地。所以来到一个新的城市,一直喜欢走遍大街小巷深度走走看看,这也是我第二天的任务。

师弟和小朋友师弟和小朋友

我和师弟我和师弟

第二天步行走街串巷逛南京城,稍后补上。

大潭郊野公园 + 港岛径五段

原计划今天去走港岛径七段,这样可以和上礼拜的八段连起来。没想到误打误撞跑到大潭郊野公园,美丽的水库景色也不枉此行。更有意思的是,沿途错过七段的路口,经过了部分六段的路线,来到了黄泥湾郊野公园。沿途很多烧烤点,适合几个朋友一起来玩,满眼绿色空气新面朝湖水大口吃串儿。

大潭郊野公园入口大潭郊野公园入口 英式拱桥远眺湖景1英式拱桥远眺湖景1

英式拱桥远眺湖景2英式拱桥远眺湖景2 英式拱桥远眺湖景3英式拱桥远眺湖景3

英式拱桥远眺湖景4英式拱桥远眺湖景4

大潭笃水库大潭笃水库 水坝水坝

水坝上游水坝上游 标准动作之一标准动作之一

标准动作之二标准动作之二 看咱们pose摆的看咱们pose摆的

这段路非常好走,加起来大概6、7公里。出来正好到了港岛径五段的路口,由于没有尽兴,我们决定再走个五段。话说港岛径一共八段,总长度50km,五段可以说是路程最短的(4km多),但是论难度无出其右(陡升到433米后突降200米,然后又陡升到420米)。更有意思的是在半山腰突遇大暴雨,被强奸了10分钟。沿途一队队老外开始往山下撤,我们躲在不会被雷劈到的岩石堆里避雨,好在那片乌云飘过之后我们可以继续前进。

半山腰俯瞰港岛南区半山腰俯瞰港岛南区

被暴雨欺负了10分钟被暴雨欺负了10分钟 湿透了湿透了 爬山如人生,高峰之后难免低谷爬山如人生,高峰之后难免低谷

真心湿透了真心湿透了 站在乌云之巅落汤鸡站在乌云之巅落汤鸡

为家花遮雨湿身为家花遮雨湿身 遥望红山半岛和来时的路遥望红山半岛和来时的路

从这个角度俯瞰维港和中环从这个角度俯瞰维港和中环 标准动作之三标准动作之三

山顶云雾缭绕山顶云雾缭绕

到了五段的终点,我们沿着quarry bay的小路直通文明世界。这段小路大概3km,全程下坡,无聊的很,可以边走边睡觉。

Omega Planet Ocean Night

movie: planet oceanmovie: planet ocean

Invited by Omega, my wife and I have a lovely chance to attend a cocktail party at IFC tonight. I should say the party is organized pretty well, a handsome and nice guy showed us around during the party and we chatted well. The cocktail tastes good, and the color echos the theme well, i.e., beautiful blue, just like the ocean.

cocktail in ocean colorcocktail in ocean color

“Planet Ocean” is a great movie produced in 2011, but the idea of “save the species, save the ocean” needs more supports from each of us. Some guys ask me why I put “lonely on the great wall” on my blog. It dates back to several years ago when I rode my bike everywhere. Sometimes, we went to the Great Wall (yes, the one in China) to collect garbages. We felt sad, because we saw people continously throwing the garbage even we were collecting them. At those sad moments, we felt so lonely.

Love the ocean, love the nature, not merely should we get to action, we should also teach our next generations.

Mr. Dahua Ren (任达华) also came, he kept fit at his age, i.e., 60. Mr. Dahua RenMr. Dahua Ren 瞅给美的瞅给美的

The party is not big, but organized neatly. the lovely cocktail partythe lovely cocktail party

Next, showtime of us couple. We even pretended to be “vampire” celebrities…

vampire couple...vampire couple… the lovely ticketsthe lovely tickets

Hello World

Migrated from wordpress to octopress now. It’s just amazing.

With such a geeky blogging framework, you can just compose your blogs in a coding style. Static web pages are generated locally by the underlying Jekyll, free from server-side craps. Anyway, you are writing plain simple blogs, aren’t you? Besides, version control can be easily handled by Git , coz even octopress itself is released/updated by Git .

What I love most is the superior deployment solution. You can choose to deploy the pages to Github page but I prefer to sync the site to my personal home page using “rsync”. If you are like me, you should be careful at the configuration on “rsync_delete” option of the Rakefile . You should know it well if you are familiar with the linux tool “rsync”. Otherwise, it may screw up all your public_html , and make you suffer from “蛋疼” badly.

Greeting in a programmer styleSource Article
1
2
3
4
5
6
7
#include <iostream>

int main ()
{
  std::cout << "Hello World" << std::endl;
  return 0;
}

Need more time to pull all my previous posts here. But I doubt whether I have to do that.

Cheers && enjoy octopress.