正在加载图片...
Example 5.2.2.3.Here we consider the problem of finding the kth smallest element of a given set of elements.The idea of the randomized algorithm for this problem is similar to RQS. Algorithm 5.2.2.4.RANDOM-SELECT(S,k) Input:S={a1,a2,...,an},n E IN,and a positive integer k<n. Step 1:if n=1 then return a1 else choose an i∈1,2,..,n randomly. 4n We can easily observe that,for every input (S,k),the worst case running time is (n2)(i.e.,there exists a sequence of random bits leading to e(n2) Output:the kth smallest element of S (i.e.,an au such that sb<a}=k-1)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有