递归函数练习题 (recursive function exams)

Recursive function is the basic and the most important of computer science, and it is widely used in solving real problems, college education (basic courses), and in the interviews for a programmer job. so, let's have some exams for it.

1. factorial . (阶乘）

given n = 3. should get result = 3x2x1 = 6given n = 5, should get result = 5x4x3x2x1

4. Tower of Hanoi

简单的说，就是计算把若干盘子从一个柱子保持原有顺序的转移到另一个柱子所需要的步骤。

given three pegs, one with a set of N disks of increasing size, determine the minimum (optimal) number of steps it takes to move all the disks from their initial position to another peg without placing a larger disk on top of a smaller one.

5. （快速排序算法）Quick Sort

对一个数组进行排序，先选定一个 pivot （中间数），然后把低于这个中间数的数组元素放到less 数组中，高于它的，放在 greater数组中。 接下来，重复这个过程，对less和 greater进行迭代. (sort an array using pivot, and patition. It first divide a large list into 2 smaller lists: less and greater, then sort them recursively )