1. Trang chủ
  2. » Giáo án - Bài giảng

Discrrete mathematics for computer science recurrence warmup

6 111 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 123,66 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Finding the Median Without SortingGeneralize to finding the k’th largest element of a list: FindL, k Median ::= FindL, |L|/2... Assume distinct elements Divide L into blocks of 5 and fin

Trang 1

Recurrence Warmup

Trang 2

Finding the Median Without Sorting

Generalize to finding the k’th largest element of a list: Find(L, k) Median ::= Find(L, |L|/2)

Trang 3

Find(L, k)

Let |L| = n Assume distinct elements

Divide L into blocks of 5 and find the medians (third of five

elements) of the blocks:

O(n) time.

Recursively find the median of the medians, M

M < half the medians, and each median < 2 of the 5 elements of its block

So those medians are < 2/10 of the elements of L

So M < 3/10 of the elements of L

Likewise M > 3/10 the elements of L

Trang 4

Find(L, k)

Use M to split L into two sublists: elements < M and elements > M

On the basis of the size of these lists, figure out which part the k’th element of L belongs to

Recursively find the corresponding element within that sublist,

which is of size at most 7n/10

Trang 5

• T(1) = 1

• T(n) ≤ T(n/5) + T(7n/10)

• (Time to find median of medians plus time to select from elements that have not been excluded)

• Linear solution!

Because n + 9n + 92n + … < 10n

So T(n) = O(n)

Trang 6

FINIS

Ngày đăng: 22/03/2019, 11:56

TỪ KHÓA LIÊN QUAN