摘要:
堆排序是一种选择排序,其最好,最坏,平均时间复杂度均为O(nlogn),是一种不稳定的排序。 首先我们来认识一下堆的结构。 对于大顶堆,其根节点的值要大于左右孩子,小顶堆则相反。那么我们可以利用满二叉树的性质,用数组来存储堆结构。i是根节点,则左右孩子为2*i和2*i+1 堆排序的算法顺序如下: 1 阅读全文
摘要:
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any 阅读全文
摘要:
There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties: (1) Every node is either 阅读全文
摘要:
map可以实现key到value的一一映射,如果是一对多的,我们可以使用multimap multimap<int,int>mp; mp.insert(make_pair(first,second)); map默认是按照key值从小到大进行排序的,如果希望按照从大到小进行排序,可以使用 map<in 阅读全文
摘要:
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open 阅读全文
摘要:
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the 阅读全文
摘要:
已知后序与中序输出前序(先序):后序:3, 4, 2, 6, 5, 1(左右根)中序:3, 2, 4, 1, 6, 5(左根右) 已知一棵二叉树,输出前,中,后时我们采用递归的方式。同样也应该利用递归的思想: 对于后序来说,最后一个节点肯定为根。在中序中可以找到左子树的个数,那么就可以在后序中找到左 阅读全文
摘要:
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any s 阅读全文