5.5 SelectionSelection refers to a class of problems that are easily r dịch - 5.5 SelectionSelection refers to a class of problems that are easily r Việt làm thế nào để nói

5.5 SelectionSelection refers to a

5.5 Selection
Selection refers to a class of problems that are easily reduced to sorting, but do
not require the full power of sorting. Let s = e1 , . . . , en be a sequence and let
s = e1 , . . . , en be the sorted version of it. Selection of the smallest element re-
quires determining e1 , selection of the smallest and the largest requires determining
e1 and en , and selection of the k-th largest requires determining ek . Selection of the
median refers to selecting the n/2 -th largest element. Selection of the median and
also quartiles is a basic problem in statistics. It is easy to determine the smallest or
the smallest and the largest element by a single scan of a sequence in linear time.
We show that the k-th largest element can also be determined in linear time. The
following simple recursive procedure solves the problem.
// Find an element with rank k
Function select(s : Sequence of Element; k : ) : Element
assert |s| ≥ k
pick p ∈ s uniformly at random
a := e ∈ s : e < p
if |a| ≥ k then return select(a, k)
b := e ∈ s : e = p
if |a| + |b| ≥ k then return p
c := e ∈ s : e > p
return select(c, k − |a| − |b|)
Fig. 5.9. Quickselect
¥
// pivot key
//
//
//
a
a
b
a
k
k
b
k
c
The procedure is akin to quicksort and is therefore called quickselect. The key
insight is that it suffices to follow one of the recursive calls, see Figure 5.9. As before,

5.5 Selection
115
a pivot is chosen and the input sequence s is partitioned into subsequences a, b, and
c containing the elements smaller than the pivot, equal to the pivot, and larger than
the pivot, respectively. If |a| ≥ k, we recurse on a, and if k > |a| + |b|, we recurse on
c, of course with a suitably adjusted k. If |a| < k ≤ |a| + |b|, the task is solved: The
pivot has rank k and we return it. Observe, that the last case also covers the situation
|s| = k = 1 and hence no special base case is needed. Figure 5.10 illustrates the
execution of quickselect.
s
3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8
3, 4, 5, 9, 6, 5, 3, 5, 8
3, 4, 5, 5, 3, 5
k
6
4
4
pabc
2123, 4, 5, 9, 6, 5, 3, 5, 8
6 3, 4, 5, 5, 3, 469, 8
53, 4, 35, 5, 5
Fig. 5.10. The execution of select( 3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8, 6 , 6). The (bold) middle ele-
ment of the current s is used as the pivot p.
As for quicksort, the worst case execution time of quickselect is quadratic. But
the expected execution time is linear and hence a logarithmic factor faster than quick-
sort.
Theorem 19. Algorithm quickselect runs in expected time O(n) on an input of size
n.
Proof. We will give an analysis that is simple and shows linear expectation. It does
not give the smallest constant possible. Let T (n) denote the expected execution time
of quickselect. Call a pivot good if neither |a| nor |b| are larger than 2n/3. Let γ
denote the probability that the pivot is good. Then γ ≥ 1/3. We now make the
conservative assumption that the problem size in the recursive call is only reduced
for good pivots and that even then it is only reduced by a factor of 2/3. Since the
work outside the recursive call is linear in n, there is an appropriate constant c such
that
T (n) ≤ cn + γT
T (n) ≤
cn
+T
γ
2n
+ (1 − γ)T (n)3
2n2n
≤ 3cn + T33
2
3
i
or, equivalently
≤ 3c(n +
2n 4n
++ . . .)
39
≤ 3cn
i≥0
≤ 3cn
Exercise 97. Modify quickselect so that it returns the k smallest elements.
Exercise 98. Give a selection algorithm that permutes an array in such a way that
the k smallest elements are in entries a[1],. . . , a[k]. No further ordering is required
except that a[k] should have rank k. Adapt the implementation tricks from array-
based quicksort to obtain a nonrecursive algorithm with fast inner loops.
1
= 9cn .
1 − 2/3

116
5 Sorting and Selection
Exercise 99 (Streaming selection).
1. Develop an algorithm that finds the k-th smallest element of a sequence that
is presented to you one element at a time in an order you cannot control. You
have only space O(k) available. This models a situation where voluminous data
arrives over a network or at a sensor.
2. Refine your algorithm so that it achieves running time O(n log k). You may want
to read some of Chapter 6 first.
*c) Refine the algorithm and its analysis further so that your algorithm runs in aver-
age case time O(n) if k = O(n/ log n). Here, average means that all presenta-
tion orders of elements in the sequence are equally likely.
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
5.5 lựa chọn
lựa chọn đề cập đến một lớp học của các vấn đề một cách dễ dàng giảm để phân loại, nhưng làm
không yêu cầu toàn bộ sức mạnh của phân loại. Cho s = e1,..., en là một chuỗi và để cho
s = e1,..., en là các phiên bản được sắp xếp của nó. Lựa chọn của các nhỏ nhất nguyên tố re-
quires xác định e1, lựa chọn nhỏ nhất và lớn nhất yêu cầu xác định
e1 và en, và lựa chọn của k-th lớn nhất yêu cầu xác định ek. Lựa chọn của các
trung vị đề cập đến việc lựa chọn các yếu tố lớn nhất -th n/2. Lựa chọn của trung bình và
cũng quartiles là một vấn đề cơ bản trong thống kê. Nó rất dễ dàng để xác định nhỏ nhất hoặc
nhỏ nhất và các yếu tố lớn nhất bởi một quét duy nhất của một trình tự trong thời gian tuyến tính.
Chúng tôi cho rằng yếu tố lớn nhất k-th cũng có thể được xác định trong thời gian tuyến tính. Các
sau đệ quy đơn giản thủ tục giải quyết problem.
// tìm thấy một nguyên tố có Xếp hạng k
hoạt động chọn (s: trình tự nguyên tố; k:): nguyên tố
khẳng định |s| ≥ k
chọn p ∈ s thống nhất ngẫu nhiên
một: = e ∈ s: e < p
nếu |a| ≥ k sau đó trở lại chọn (a, k)
b: = e ∈ s: e = p
nếu |a| |b| ≥ k sau đó trở về p
c:= e ∈ s: e > p
trở lại chọn (c, k − |a| − |b|)
Hình 5.9. Quickselect
¥
/ / trục phím
/ /
/ /
/ /
một
một
b
một
k
k
b
k
c
các thủ tục là giống như hay Hoaresort và do đó được gọi là quickselect. Chìa khóa
cái nhìn sâu sắc là nó suffices để đi theo một trong các cuộc gọi đệ quy, xem hình 5.9. Như trước,

5.5 lựa chọn
115
một pivot được lựa chọn và nhập chuỗi s phân chia thành subsequences a, b, và
c có chứa các yếu tố nhỏ hơn so với trục, tương đương với trục, và lớn hơn
pivot, tương ứng. Nếu |a| ≥ k, chúng tôi recurse trên một, và nếu k > |a| |b|, chúng tôi recurse trên
c, tất nhiên với một k điều chỉnh phù hợp. Nếu |a| < k ≤ |a| |b|, nhiệm vụ được giải quyết: The
pivot đã xếp hạng k và chúng tôi trở lại nó. Quan sát, các trường hợp mới cũng bao gồm tình hình
|s| = k = 1 và do đó không có trường hợp cơ sở đặc biệt cần thiết. 5.10 hình minh họa các
thực hiện quickselect.
s
3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8
3, 4, 5, 9, 6, 5, 3, 5, 8
3, 4, 5, 5, 3, 5
k
6
4
4
pabc
2123, 4, 5, 9, 6, 5, 3, 5, 8
6 3, 4, 5, 5, 3, 469, 8
53, 4, 35, 5, 5
hình 5.10. Thực hiện lựa chọn (3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8, 6, 6). Ele (đậm) giữa-
ment của s hiện tại được sử dụng như pivot p.
đối với hay Hoaresort, thời gian thực hiện trường hợp xấu nhất của quickselect là bậc hai. Nhưng
thời gian thực hiện dự kiến là tuyến tính và vì thế một yếu tố lôgarít nhanh hơn nhanh chóng-
loại.
định lý 19. Thuật toán quickselect chạy trong thời gian dự kiến O(n) trên một đầu vào kích thước
n.
bằng chứng. Chúng tôi sẽ cung cấp cho một phân tích đó là đơn giản và cho thấy tuyến tính kỳ vọng. Nó
không cung cấp cho hằng số nhỏ nhất có thể. Hãy T (n) biểu thị thời gian thực hiện dự kiến
của quickselect. Gọi một pivot tốt nếu không |a| và cũng không |b| lớn hơn 2n/3. Hãy để γ
biểu thị khả năng rằng trục là tốt. Sau đó γ ≥ 1/3. Chúng tôi bây giờ làm cho các
bảo thủ giả định rằng kích thước vấn đề trong cuộc gọi đệ quy chỉ giảm
cho tốt pivots và thậm chí sau đó nó chỉ giảm xuống bởi một nhân tố của 2/3. Kể từ khi các
làm việc bên ngoài gọi đệ quy là tuyến tính trong n, có một c liên tục thích hợp như vậy

T (n) ≤ cn γT
T (n) ≤
cn
T
γ
2n
(1 − γ) T (n) 3
2n2n
≤ 3cn T33
2
3
tôi
hoặc tương đương
≤ 3c (n
2n 4n
...)
39
≤ 3cn
i≥0
≤ 3cn
tập thể dục 97. Sửa đổi quickselect để nó trả về k yếu tố nhỏ nhất.
tập thể dục 98. Cung cấp cho một thuật toán lựa chọn permutes một mảng trong một cách mà
k nhỏ nhất yếu tố nằm trong mục [1],..., [k]. Không có thứ tự là yêu cầu
ngoại trừ rằng một [k] nên có Xếp hạng k. thích ứng với các thủ đoạn thực hiện từ mảng-
dựa hay Hoaresort để có được một thuật toán nonrecursive với nhanh bên trong vòng
1
= 9cn.
1 − 2/3

116
5 phân loại và lựa chọn
tập thể dục 99 (Streaming lựa chọn).
1. Phát triển một thuật toán mà finds các yếu tố nhỏ nhất k-th của một chuỗi đó
được trình bày cho bạn một phần tại một thời điểm trong một đơn đặt hàng bạn không thể kiểm soát. Bạn
có chỉ chứa O(k) có sẵn. Điều này mô hình tình hình một nơi chia làm nhiều quyển dữ liệu
đến qua mạng hoặc tại một cảm biến.
2. Refine thuật toán của bạn vì vậy mà nó đạt được thời gian chạy O (n log k). Bạn có thể muốn
để đọc một số chương 6 vòng.
* c) Refine các thuật toán và phân tích của nó tiếp tục vì vậy mà thuật toán của bạn chạy aver-
tuổi trường hợp thời gian O(n) nếu k = O (n/log n). Ở đây, là có nghĩa là tất cả presenta-
tion đơn đặt hàng của các yếu tố trong chuỗi có khả năng như nhau.
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
5.5 Selection
Selection refers to a class of problems that are easily reduced to sorting, but do
not require the full power of sorting. Let s = e1 , . . . , en be a sequence and let
s = e1 , . . . , en be the sorted version of it. Selection of the smallest element re-
quires determining e1 , selection of the smallest and the largest requires determining
e1 and en , and selection of the k-th largest requires determining ek . Selection of the
median refers to selecting the n/2 -th largest element. Selection of the median and
also quartiles is a basic problem in statistics. It is easy to determine the smallest or
the smallest and the largest element by a single scan of a sequence in linear time.
We show that the k-th largest element can also be determined in linear time. The
following simple recursive procedure solves the problem.
// Find an element with rank k
Function select(s : Sequence of Element; k : ) : Element
assert |s| ≥ k
pick p ∈ s uniformly at random
a := e ∈ s : e < p
if |a| ≥ k then return select(a, k)
b := e ∈ s : e = p
if |a| + |b| ≥ k then return p
c := e ∈ s : e > p
return select(c, k − |a| − |b|)
Fig. 5.9. Quickselect
¥
// pivot key
//
//
//
a
a
b
a
k
k
b
k
c
The procedure is akin to quicksort and is therefore called quickselect. The key
insight is that it suffices to follow one of the recursive calls, see Figure 5.9. As before,

5.5 Selection
115
a pivot is chosen and the input sequence s is partitioned into subsequences a, b, and
c containing the elements smaller than the pivot, equal to the pivot, and larger than
the pivot, respectively. If |a| ≥ k, we recurse on a, and if k > |a| + |b|, we recurse on
c, of course with a suitably adjusted k. If |a| < k ≤ |a| + |b|, the task is solved: The
pivot has rank k and we return it. Observe, that the last case also covers the situation
|s| = k = 1 and hence no special base case is needed. Figure 5.10 illustrates the
execution of quickselect.
s
3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8
3, 4, 5, 9, 6, 5, 3, 5, 8
3, 4, 5, 5, 3, 5
k
6
4
4
pabc
2123, 4, 5, 9, 6, 5, 3, 5, 8
6 3, 4, 5, 5, 3, 469, 8
53, 4, 35, 5, 5
Fig. 5.10. The execution of select( 3, 1, 4, 5, 9, 2, 6, 5, 3, 5, 8, 6 , 6). The (bold) middle ele-
ment of the current s is used as the pivot p.
As for quicksort, the worst case execution time of quickselect is quadratic. But
the expected execution time is linear and hence a logarithmic factor faster than quick-
sort.
Theorem 19. Algorithm quickselect runs in expected time O(n) on an input of size
n.
Proof. We will give an analysis that is simple and shows linear expectation. It does
not give the smallest constant possible. Let T (n) denote the expected execution time
of quickselect. Call a pivot good if neither |a| nor |b| are larger than 2n/3. Let γ
denote the probability that the pivot is good. Then γ ≥ 1/3. We now make the
conservative assumption that the problem size in the recursive call is only reduced
for good pivots and that even then it is only reduced by a factor of 2/3. Since the
work outside the recursive call is linear in n, there is an appropriate constant c such
that
T (n) ≤ cn + γT
T (n) ≤
cn
+T
γ
2n
+ (1 − γ)T (n)3
2n2n
≤ 3cn + T33
2
3
i
or, equivalently
≤ 3c(n +
2n 4n
++ . . .)
39
≤ 3cn
i≥0
≤ 3cn
Exercise 97. Modify quickselect so that it returns the k smallest elements.
Exercise 98. Give a selection algorithm that permutes an array in such a way that
the k smallest elements are in entries a[1],. . . , a[k]. No further ordering is required
except that a[k] should have rank k. Adapt the implementation tricks from array-
based quicksort to obtain a nonrecursive algorithm with fast inner loops.
1
= 9cn .
1 − 2/3

116
5 Sorting and Selection
Exercise 99 (Streaming selection).
1. Develop an algorithm that finds the k-th smallest element of a sequence that
is presented to you one element at a time in an order you cannot control. You
have only space O(k) available. This models a situation where voluminous data
arrives over a network or at a sensor.
2. Refine your algorithm so that it achieves running time O(n log k). You may want
to read some of Chapter 6 first.
*c) Refine the algorithm and its analysis further so that your algorithm runs in aver-
age case time O(n) if k = O(n/ log n). Here, average means that all presenta-
tion orders of elements in the sequence are equally likely.
đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2024 I Love Translation. All reserved.

E-mail: