摘要:
转载:http://www.cppblog.com/humanchao/archive/2012/11/12/47357.html问题一:有一个单链表,其中可能有一个环,也就是某个节点的next指向的是链表中在它之前的节点,这样在链表的尾部形成一环。问题:1、如何判断一个链表是不是这类链表?2、如果链表为存在环,如何找到环的入口点?解答:一、判断单链表是否存在环,办法为:设置两个指针(fast, slow),初始值都指向头,slow每次前进一步,fast每次前进二步,如果链表存在环,则fast必定先进入环,而slow后进入环,两个指针必定相遇。(当然,fast先行头到尾部为NULL,则为无环链 阅读全文
摘要:
Describe a red-black tree on n keys that realizes the largest possible ratio of red in-ternal nodes to black internal nodes. What is this ratio? What tree has the smallestpossible ratio, and what is the ratio?Solution:1. Largest possible ration Red node is as many as possible. h = [lg(k)]. Ration .. 阅读全文