We now show that the above deterministic selection algorithm runs in linear time.
The algorithm has two recursive calls. The first one is performed on the set of
baby medians, which has size
g = ⌈n/5⌉.
The second recursive call is made on either set L (elements smaller than the pivot,
x) or set G (elements larger than the pivot, x). Recall that each group but one
contains 5 elements and our pivot, x, is the median of the baby medians from all
of these groups. Thus, we have that for ⌈g/2⌉ groups, at least half of the group
elements are less than or equal to x. Since group Sg could be part of this half, we
have that number of elements in S that are less than or equal to x is at least
3
34g
2
5
− 1
6
+1=3 7
1
2 ·
4n
5
58
− 2 ≥
3n
10 − 2.
With a similar argument, we obtain that the above value is also a lower bound on
the number of elements of S less than or equal to x.
We conclude that the second recursive call is performed on a set of size at most
n −
13n
10 − 2
2
= 7n
10 + 2.
Overall, for a sufficiently large value of n, the running time for the deterministic
selection algorithm, T(n), can be characterized by the following recurrence
relation:
T(n) ≤ T(n/5 + 1) + T(7n/10 + 2) + bn.
where b > 0 is a constant.
To solve the recurrence, we guess that T(n) ≤ cn, for some constant c > 0.
Expanding the recurrence, we have the following:
T(n) ≤ T(n/5 + 1) + T(7n/10 + 2) + bn
≤ cn/5 + c + 7cn/10 + 2c + bn
= 9cn/10 + bn + 3c.
Pick c = 11b. We obtain
T(n) ≤ 9cn/10 + bn + 3c ≤ 9cn/10 + cn/11 + 3c.
Thus, we have T(n) ≤ cn for n large enough such that
cn/11 + 3c ≤ cn/10,
that is, for n ≥ 330. Therefore, the running time of the deterministic selection
algorithm is O(n).
We summarize the above analysis with the following theorem
ตอนนี้เราแสดงให้เห็นว่าขั้นตอนวิธีการเลือกกำหนดข้างต้นทำงานในเส้นเวลา.
อัลกอริทึมมีสองสาย recursive คนแรกที่จะดำเนินการในชุดของ
มีเดียทารกซึ่งมีขนาด
g = ⌈n / 5⌉.
โทร recursive ที่สองคือการทำในทั้งชุด L (องค์ประกอบขนาดเล็กกว่าเดือย,
X) หรือตั้งค่า G (องค์ประกอบที่มีขนาดใหญ่กว่า หมุน x) จำได้ว่าแต่ละกลุ่ม แต่อย่างหนึ่ง
มี 5 องค์ประกอบและหมุนของเรา, X, เป็นค่ามัธยฐานของมีเดียทารกจากทุก
กลุ่มเหล่านี้ ดังนั้นเราจึงมีว่าสำหรับ⌈g / 2⌉กลุ่มอย่างน้อยครึ่งหนึ่งของกลุ่ม
องค์ประกอบน้อยกว่าหรือเท่ากับ x เนื่องจากกลุ่ม Sg อาจเป็นส่วนหนึ่งของครึ่งปีนี้เรา
มีจำนวนขององค์ประกอบใน S ที่น้อยกว่าหรือเท่ากับ x อย่างน้อย
3
34g
2
5
- 1
6
+ 1 = 3 7
1
2 ·
4n
5
58
- 2 ≥
3N
10 - 2.
ด้วยการโต้แย้งที่คล้ายกันเราได้รับว่ามูลค่าดังกล่าวยังเป็นที่ถูกผูกไว้ในที่ต่ำกว่า
. จำนวนขององค์ประกอบของ S น้อยกว่าหรือเท่ากับ x
เราสรุปได้ว่าโทร recursive ที่สองคือการดำเนินการเกี่ยวกับการตั้งค่าของขนาดที่ ส่วนใหญ่
n -
13n
10 - 2
2
= 7N
10 + 2
โดยรวมสำหรับค่ามากพอของ n, เวลาการทำงานสำหรับการกำหนด
ขั้นตอนวิธีการเลือก T (n) สามารถโดดเด่นด้วยการเกิดขึ้นอีกต่อไป
ความสัมพันธ์:
T (n ) ≤ T (n / 5 + 1) + T (7N / 10 + 2) + BN.
ที่ b> 0 เป็นค่าคงที่.
เพื่อแก้ปัญหาการเกิดซ้ำที่เราเดาว่า T (n) ≤ CN สำหรับบางคนคง C> 0.
ขยายการเกิดซ้ำเรามีดังต่อไปนี้:
T (n) ≤ T (n / 5 + 1) + T (7N / 10 + 2) + BN
≤ CN / 5 + C + 7cn / 10 + 2C + BN
= 9cn / 10 + พันล้าน + 3C.
เลือก c = 11B เราได้รับ
T (n) ≤ 9cn / 10 + พันล้าน + 3C ≤ 9cn / 10 + CN / 11 + 3C.
ดังนั้นเราจึงมี T (n) ≤ CN สำหรับ n มากพอเช่นนั้น
CN / 11 + 3C ≤ CN / 10 ,
ที่อยู่, สำหรับ n ≥ 330 ดังนั้นเวลาทำงานของตัวเลือกที่กำหนด
ขั้นตอนวิธีการเป็น O (n.)
บริษัท ฯ ได้สรุปการวิเคราะห์ข้างต้นด้วยทฤษฎีบทดังต่อไปนี้
การแปล กรุณารอสักครู่..
