Wednesday, September 10, 2014

基础概念题

1. what is a hash table?
answer: Hash table is a data structure to implemented associated array, a structure that can map keys to values. A hash table uses a hash function to compute a index into an array of buckets or slots, from which the correct value could be found.

hashtable一般会问open addressing的实现
 注意一下rehash就好了
链表hash不是纯没技术含量么。。。
而且一般正经的库里也不用链表的实现





2. what is the difference between a pointer and a reference in c++?

answer: They are completely different type of concepts. A reference is an alias of a object. A pointer is an object contains address pointed to another object.

3. explain the various uses of keyword "static" in c++?

answer: In C++, there are 3 different use of keyword static: local static objects, static class data members and static class member functions.

A local static objects is a local objects whose value persist across calls to the function. It is initialized before the first time execution pass through the object's definition. The local static objects are not destroyed when function call ends. They are destroyed when program ends.

Static data members of a class exist outside any objects of its class type. They are not initialized by class' constructors. More over, we must initialize each static data member outside the class body(except const static data member). Once they are defined, they exist until program ends.

Static member functions are also not bound to any objects. They cannot access non-static data members of the class. They do not have "this" pointer, as a result, may not be declared as const. Both static data members and static member function can be accessed by a scope operator "::".

4. 一个空的class 的大小?
answer: 1 byte.

5. 有没有virtual constructor?
answer: no.

6. heap sort
heapsort两个部分

一个是由下而上的heapify,用来从数组生成heap
另一个是从heap顶端弄出来一个元素和结尾的元素交换,然后重新heapify
哦,后面这个操作较heapify
前面那个一般叫make heap


No comments:

Post a Comment