#### ALGORITHM

### The significance of coding competition to actual work

Some friends asked this question: In secondary schools we participate in the NOI, in university we participate in ACM/ICPC, TopCoder.What's the significance of coding competition to actual work? I participated in the NOI from 1994 to 1996, ACM/ICPC from 1999 to 2000 and TopCoder in 2002 for six months. Later I paid little attention to coding competition, so I may not understand the changes in recent years and race mode . The capabilities we can get by participating the competition can be summari...

2,048 0 0 PROGRAMMING FACEBOOK ACM TOPCODER

### Find the kth smallest number in an array

This is an classical question, the general solution to this question is first using sorting algorithm to sort the array, then get the kth number in the array, the complexity is O(nlogn), we can also use selective sort or head sort to, the complexity of selective sort is O(kn) and heap sort is O(nlogk). The better solution is to use quick sort to find the kth smallest number, the complexity is O(n), the worst case cost is O(n^2). But today we introduce one more solution which has the worst case c...

4,284 0 0 SORT SEARCH QUICK SORT SMALLEST

### Gaussian Blur Algorithm

Usually, image processing software will provide blur filter to make images blur. There are many algorithms to implement blur, one of them is called Gaussian Blur algorithm. It utilizes Gaussian distribution to process images. This article is to introduce Gaussian Blur algorithm, you will find this a simple algorithm. In fact, it is a kind of data smoothing which can be used in many situations. 1. Gaussian Blur theory The so called blur can be understood as taking a pixel as the average value of...

51,505 1 17 ALGORITHM GAUSSIAN BLUR IMAGE BLUR

### Significance and use of do{...}while(0)

In some Linux kernel and other open source codes, we can see some codes like below: do{ ... }while(0) This code snippet is not a loop, it seems there is no significance of using do...while this way, then why should we use it? In fact, the significance of do{...}while(0) is better than optimizing your code. After some research, we summarize some benefits of it. 1. Help define complex macro to avoid error #define DOSOMETHING()\ foo1();\ foo2(); The me...

3,068 0 0 DO{...}WHILE(0) OPTIMIZATION

### Integer overflow

You may be familiar with integer overflow, but what you may not be familiar with is how gcc handles signed integer overflow. First let's look at the standard, for unsigned integer, the standard says : A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type. In other words, unsigned integer ov...

2,846 0 1 LINUX GCC INTEGER OVERFLOW

### Implementation of Tower of Hanoi

The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following rules: Only one disk may be moved at a time. Each move consists of taking the upper disk fro...

2,260 0 0 ALGORITHM TOWER OF HANOI

### Implementation of +,-,*,/ with bitwise operator

There is a question asked on Stackoverflow : Divide a number by 3 without using *,/,+,-,% operators. This question is an Oracle interview question. Some people give excellent answers. You can go there and take a look. Usually we need to use bitwise operators to do this kind of implementations. Here I want to show you ways to implement +,-,*,/ with bitwise operators. A bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, pr...

25,908 3 4 DIVISION BITWISE OPERATOR SHIFT ADD SUBTRACT MULTIPLICATION

### How regular expression works

Rob Pike wrote 30 lines of codes to realize a simple regular expression matcher in his book The practice of Programming. This piece of code is really cool. Let's take a look at the code.Meaning of different characters.Character Meaning c General character . Match any single character ^ Match start of a string $ Match end of a string * Match zero or many occurrences of a character /*match ：Test the regexp in text*/int match(char* regexp,char* text){ if(regexp[0] == '^') ...

2,145 0 0 C REGULAR EXPRESSION IMPLEMENTATION ROB PIKE