算法导论学习笔记-2

1 stack

  FIRST IN, LAST OUT

  写一个小程序,通过array来完成stackpush , 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值