
algorithm
文章平均质量分 61
rx_wen
这个作者很懒,什么都没留下…
展开
-
Ex5.1-3 of Introduction to Algorithms
Question: Suppose that you want to output 0 with probability 1/2 and 1 with probability 1/2. At your disposal is a procedure BIASED-RANDOM, that outputs either 0 or 1. It outputs 1 with some probability p and 0 with probability 1 - p, where 0 = p) rc原创 2009-12-04 13:04:00 · 870 阅读 · 0 评论 -
Ex 10.4-3 of introduction to algorithms
Question:Write an O(n)-time nonrecursive procedure that, given an n-node binary tree, prints out the key of each node in the tree. Use a stack as an auxiliary data structure. Answer:This isn't a difficult question. But the skill of turning a recursive algo原创 2009-12-24 17:04:00 · 622 阅读 · 0 评论 -
Ex5.1-2 of introduction to algorithms
A friend asked my idea about the exercise 5.1-2 of introduction to algorithms. Here is the original question:Question:Describe an implementation of the procedure RANDOM(a, b) that only makes calls to RANDOM(0, 1). What is the expected running time of your原创 2009-12-02 08:25:00 · 570 阅读 · 0 评论 -
Ex 15.4-5 of introduction to algorithms
Question:Give an O(n squared)-time algorithm to find the longest monotonically increasing subsequence of a sequence of n numbers.Answer:A brute-force approach is enumerate all subsequences of the n numbers and find out a monotonically increasing one with t原创 2010-01-20 12:01:00 · 897 阅读 · 0 评论 -
Ex 9.3-8 of Introduction to algorithms
Question:Let X[1 .. n] and Y [1 .. n] be two arrays, each containing n numbers already in sorted order. Give an O(lg n)-time algorithm to find the median of all 2n elements in arrays X and Y.Answer:Without losing generality, suppose the median z is the sma原创 2009-12-17 08:49:00 · 512 阅读 · 0 评论