1 stack
FIRST IN, LAST OUT
写一个小程序,通过array来完成stack的push , pop操作。注意检查underflow , overflow情况
2 queue
FIRST IN, FIRST OUT
注意,When head[Q] = tail[Q] + 1, the queue is full
写一个小程序,通过array完成ENQUEUE(Q, x) , DEQUEUE(Q)。注意检查underflow , overflow情况
3 hash
It is a method that accesses an element in a Set with constant time.
a : hash(k)=x , x point to the element , the key of the element is k
b : when hash(k1)=hash(k2)=x , then collision happens. Because the two elements have the same pointer [address]
a popular method to resolves a collision is chaining—chaining the elements that have the same the hash values.
Chapter 11 introduces hash tables, which support the dictionary operations INSERT,DELETE, and SEARCH. In the worst case, hashing requires Θ(n) time to perform a SEARCH operation, but the expected time for hash-table operations is O(1). The analysis of hashing relies on probability, but most of the chapter requires no background in the subject.
-----------------------------------
Binary search trees, which are covered in Chapter 12, support all the dynamic-set operations
listed above. In the worst case, each operation takes Θ(n) time on a tree with n elements, but
on a randomly built binary search tree, the expected time for each operation is O(lg n). Binary
search trees serve as the basis for many other data structures.
-----------------------------------
Red-black trees, a variant of binary search trees, are introduced in Chapter 13. Unlike ordinary binary search trees, red-black trees are guaranteed to perform well: operations take
O(lg n) time in the worst case. A red-black tree is a balanced search tree; Chapter 18 presents
another kind of balanced search tree, called a B-tree. Although the mechanics of red-black
trees are somewhat intricate, you can glean most of their properties from the chapter without
studying the mechanics in detail. Nevertheless, walking through the code can be quite
instructive.